@@ -94,6 +94,7 @@ class TestIndexing(tm.TestCase):
94
94
_typs = set (['ints' ,'labels' ,'mixed' ,'ts' ,'floats' ,'empty' ])
95
95
96
96
def setUp (self ):
97
+
97
98
import warnings
98
99
warnings .filterwarnings (action = 'ignore' , category = FutureWarning )
99
100
@@ -3220,6 +3221,64 @@ def test_ix_empty_list_indexer_is_ok(self):
3220
3221
assert_frame_equal (df .ix [:,[]], df .iloc [:, :0 ]) # vertical empty
3221
3222
assert_frame_equal (df .ix [[],:], df .iloc [:0 , :]) # horizontal empty
3222
3223
3224
+ def test_deprecate_float_indexers (self ):
3225
+
3226
+ # GH 4892
3227
+ # deprecate allowing float indexers that are equal to ints to be used
3228
+ # as indexers in non-float indices
3229
+
3230
+ import warnings
3231
+ warnings .filterwarnings (action = 'error' , category = FutureWarning )
3232
+
3233
+ for index in [ tm .makeStringIndex , tm .makeUnicodeIndex ,
3234
+ tm .makeDateIndex , tm .makePeriodIndex ]:
3235
+
3236
+ i = index (5 )
3237
+ s = Series (np .arange (len (i )),index = i )
3238
+ self .assertRaises (FutureWarning , lambda :
3239
+ s .iloc [3.0 ])
3240
+ self .assertRaises (FutureWarning , lambda :
3241
+ s [3.0 ])
3242
+
3243
+ # this is ok!
3244
+ s [3 ]
3245
+
3246
+ # ints
3247
+ i = index (5 )
3248
+ s = Series (np .arange (len (i )))
3249
+ self .assertRaises (FutureWarning , lambda :
3250
+ s .iloc [3.0 ])
3251
+
3252
+ # on some arch's this doesn't provide a warning (and thus raise)
3253
+ # and some it does
3254
+ try :
3255
+ s [3.0 ]
3256
+ except :
3257
+ pass
3258
+
3259
+ # floats: these are all ok!
3260
+ i = np .arange (5. )
3261
+ s = Series (np .arange (len (i )),index = i )
3262
+ with tm .assert_produces_warning (False ):
3263
+ s [3.0 ]
3264
+
3265
+ with tm .assert_produces_warning (False ):
3266
+ s [3 ]
3267
+
3268
+ with tm .assert_produces_warning (False ):
3269
+ s .iloc [3.0 ]
3270
+
3271
+ with tm .assert_produces_warning (False ):
3272
+ s .iloc [3 ]
3273
+
3274
+ with tm .assert_produces_warning (False ):
3275
+ s .loc [3.0 ]
3276
+
3277
+ with tm .assert_produces_warning (False ):
3278
+ s .loc [3 ]
3279
+
3280
+ warnings .filterwarnings (action = 'ignore' , category = FutureWarning )
3281
+
3223
3282
if __name__ == '__main__' :
3224
3283
import nose
3225
3284
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments