@@ -233,8 +233,7 @@ def inc(x):
233
233
expected = pd .DataFrame ([[- 1 , inc ], [inc , - 1 ]])
234
234
tm .assert_frame_equal (df , expected )
235
235
236
- def test_getitem_boolean (self , float_string_frame , mixed_float_frame ,
237
- mixed_int_frame , datetime_frame ):
236
+ def test_getitem_boolean_from_datetime (self , datetime_frame ):
238
237
# boolean indexing
239
238
d = datetime_frame .index [10 ]
240
239
indexer = datetime_frame .index > d
@@ -269,27 +268,65 @@ def test_getitem_boolean(self, float_string_frame, mixed_float_frame,
269
268
assert_frame_equal (subframe_obj , subframe )
270
269
271
270
# test df[df > 0]
272
- for df in [datetime_frame , float_string_frame ,
273
- mixed_float_frame , mixed_int_frame ]:
274
- if compat .PY3 and df is float_string_frame :
275
- continue
271
+ df = datetime_frame
272
+ data = df ._get_numeric_data ()
273
+ bif = df [df > 0 ]
274
+ bifw = DataFrame ({c : np .where (data [c ] > 0 , data [c ], np .nan )
275
+ for c in data .columns },
276
+ index = data .index , columns = data .columns )
277
+
278
+ # add back other columns to compare
279
+ for c in df .columns :
280
+ if c not in bifw :
281
+ bifw [c ] = df [c ]
282
+ bifw = bifw .reindex (columns = df .columns )
283
+
284
+ assert_frame_equal (bif , bifw , check_dtype = False )
285
+ for c in df .columns :
286
+ if bif [c ].dtype != bifw [c ].dtype :
287
+ assert bif [c ].dtype == df [c ].dtype
288
+
289
+ def test_getitem_boolean_from_mixed_float (self , mixed_float_frame ):
290
+ df = mixed_float_frame
276
291
277
- data = df ._get_numeric_data ()
278
- bif = df [df > 0 ]
279
- bifw = DataFrame ({c : np .where (data [c ] > 0 , data [c ], np .nan )
280
- for c in data .columns },
281
- index = data .index , columns = data .columns )
282
-
283
- # add back other columns to compare
284
- for c in df .columns :
285
- if c not in bifw :
286
- bifw [c ] = df [c ]
287
- bifw = bifw .reindex (columns = df .columns )
288
-
289
- assert_frame_equal (bif , bifw , check_dtype = False )
290
- for c in df .columns :
291
- if bif [c ].dtype != bifw [c ].dtype :
292
- assert bif [c ].dtype == df [c ].dtype
292
+ # test df[df > 0]
293
+ data = df ._get_numeric_data ()
294
+ bif = df [df > 0 ]
295
+ bifw = DataFrame ({c : np .where (data [c ] > 0 , data [c ], np .nan )
296
+ for c in data .columns },
297
+ index = data .index , columns = data .columns )
298
+
299
+ # add back other columns to compare
300
+ for c in df .columns :
301
+ if c not in bifw :
302
+ bifw [c ] = df [c ]
303
+ bifw = bifw .reindex (columns = df .columns )
304
+
305
+ assert_frame_equal (bif , bifw , check_dtype = False )
306
+ for c in df .columns :
307
+ if bif [c ].dtype != bifw [c ].dtype :
308
+ assert bif [c ].dtype == df [c ].dtype
309
+
310
+ def test_getitem_boolean_from_mixed_int (self , mixed_int_frame ):
311
+ df = mixed_int_frame
312
+
313
+ # test df[df > 0]
314
+ data = df ._get_numeric_data ()
315
+ bif = df [df > 0 ]
316
+ bifw = DataFrame ({c : np .where (data [c ] > 0 , data [c ], np .nan )
317
+ for c in data .columns },
318
+ index = data .index , columns = data .columns )
319
+
320
+ # add back other columns to compare
321
+ for c in df .columns :
322
+ if c not in bifw :
323
+ bifw [c ] = df [c ]
324
+ bifw = bifw .reindex (columns = df .columns )
325
+
326
+ assert_frame_equal (bif , bifw , check_dtype = False )
327
+ for c in df .columns :
328
+ if bif [c ].dtype != bifw [c ].dtype :
329
+ assert bif [c ].dtype == df [c ].dtype
293
330
294
331
def test_getitem_boolean_casting (self , datetime_frame ):
295
332
0 commit comments