Repository: pandas-dev/pandas

Issue:
DEPR: deprecate float keys in non-float indexers
see #4850 

`Series(range(5))[3.0]`

is accepted in 0.13, but ought to be deprecated (and warned)

ideally raise a `TypeError` after some transition period

note this does not really affect positional indexing fallback per se, 



Discussion:

Resolving patch:
diff --git a/pandas/core/index.py b/pandas/core/index.py
--- a/pandas/core/index.py
+++ b/pandas/core/index.py
@@ -1,6 +1,7 @@
 # pylint: disable=E1101,E1103,W0232
 import datetime
 from functools import partial
+import warnings
 from pandas.compat import range, zip, lrange, lzip, u, reduce
 from pandas import compat
 import numpy as np
@@ -468,11 +469,19 @@ def to_int():
             return ikey
 
         if typ == 'iloc':
-            if not (is_integer(key) or is_float(key)):
-                self._convert_indexer_error(key, 'label')
-            return to_int()
+            if is_integer(key):
+                return key
+            elif is_float(key):
+                if not self.is_floating():
+                    warnings.warn("scalar indexers for index type {0} should be integers and not floating point".format(
+                        type(self).__name__),FutureWarning)
+                return to_int()
+            return self._convert_indexer_error(key, 'label')
 
         if is_float(key):
+            if not self.is_floating():
+                warnings.warn("scalar indexers for index type {0} should be integers and not floating point".format(
+                    type(self).__name__),FutureWarning)
             return to_int()
 
         return key


Test patch:
diff --git a/pandas/tests/test_indexing.py b/pandas/tests/test_indexing.py
--- a/pandas/tests/test_indexing.py
+++ b/pandas/tests/test_indexing.py
@@ -94,6 +94,7 @@ class TestIndexing(tm.TestCase):
     _typs = set(['ints','labels','mixed','ts','floats','empty'])
 
     def setUp(self):
+
         import warnings
         warnings.filterwarnings(action='ignore', category=FutureWarning)
 
@@ -3220,6 +3221,64 @@ def test_ix_empty_list_indexer_is_ok(self):
         assert_frame_equal(df.ix[:,[]], df.iloc[:, :0])  # vertical empty
         assert_frame_equal(df.ix[[],:], df.iloc[:0, :])  # horizontal empty
 
+    def test_deprecate_float_indexers(self):
+
+        # GH 4892
+        # deprecate allowing float indexers that are equal to ints to be used
+        # as indexers in non-float indices
+
+        import warnings
+        warnings.filterwarnings(action='error', category=FutureWarning)
+
+        for index in [ tm.makeStringIndex, tm.makeUnicodeIndex,
+                       tm.makeDateIndex, tm.makePeriodIndex ]:
+
+            i = index(5)
+            s = Series(np.arange(len(i)),index=i)
+            self.assertRaises(FutureWarning, lambda :
+                              s.iloc[3.0])
+            self.assertRaises(FutureWarning, lambda :
+                              s[3.0])
+
+            # this is ok!
+            s[3]
+
+        # ints
+        i = index(5)
+        s = Series(np.arange(len(i)))
+        self.assertRaises(FutureWarning, lambda :
+                          s.iloc[3.0])
+
+        # on some arch's this doesn't provide a warning (and thus raise)
+        # and some it does
+        try:
+            s[3.0]
+        except:
+            pass
+
+        # floats: these are all ok!
+        i = np.arange(5.)
+        s = Series(np.arange(len(i)),index=i)
+        with tm.assert_produces_warning(False):
+            s[3.0]
+
+        with tm.assert_produces_warning(False):
+            s[3]
+
+        with tm.assert_produces_warning(False):
+            s.iloc[3.0]
+
+        with tm.assert_produces_warning(False):
+            s.iloc[3]
+
+        with tm.assert_produces_warning(False):
+            s.loc[3.0]
+
+        with tm.assert_produces_warning(False):
+            s.loc[3]
+
+        warnings.filterwarnings(action='ignore', category=FutureWarning)
+
 if __name__ == '__main__':
     import nose
     nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],