@@ -288,7 +288,7 @@ def test_setattr_column(self):
288
288
df .foobar = 5
289
289
assert (df .foobar == 5 ).all ()
290
290
291
- def test_setitem (self , float_frame , using_copy_on_write ):
291
+ def test_setitem (self , float_frame , using_copy_on_write , using_infer_string ):
292
292
# not sure what else to do here
293
293
series = float_frame ["A" ][::2 ]
294
294
float_frame ["col5" ] = series
@@ -331,7 +331,10 @@ def test_setitem(self, float_frame, using_copy_on_write):
331
331
with pytest .raises (SettingWithCopyError , match = msg ):
332
332
smaller ["col10" ] = ["1" , "2" ]
333
333
334
- assert smaller ["col10" ].dtype == np .object_
334
+ if using_infer_string :
335
+ assert smaller ["col10" ].dtype == "string"
336
+ else :
337
+ assert smaller ["col10" ].dtype == np .object_
335
338
assert (smaller ["col10" ] == ["1" , "2" ]).all ()
336
339
337
340
def test_setitem2 (self ):
@@ -426,7 +429,7 @@ def test_setitem_cast(self, float_frame):
426
429
float_frame ["something" ] = 2.5
427
430
assert float_frame ["something" ].dtype == np .float64
428
431
429
- def test_setitem_corner (self , float_frame ):
432
+ def test_setitem_corner (self , float_frame , using_infer_string ):
430
433
# corner case
431
434
df = DataFrame ({"B" : [1.0 , 2.0 , 3.0 ], "C" : ["a" , "b" , "c" ]}, index = np .arange (3 ))
432
435
del df ["B" ]
@@ -463,10 +466,16 @@ def test_setitem_corner(self, float_frame):
463
466
dm ["foo" ] = "bar"
464
467
del dm ["foo" ]
465
468
dm ["foo" ] = "bar"
466
- assert dm ["foo" ].dtype == np .object_
469
+ if using_infer_string :
470
+ assert dm ["foo" ].dtype == "string"
471
+ else :
472
+ assert dm ["foo" ].dtype == np .object_
467
473
468
474
dm ["coercible" ] = ["1" , "2" , "3" ]
469
- assert dm ["coercible" ].dtype == np .object_
475
+ if using_infer_string :
476
+ assert dm ["coercible" ].dtype == "string"
477
+ else :
478
+ assert dm ["coercible" ].dtype == np .object_
470
479
471
480
def test_setitem_corner2 (self ):
472
481
data = {
@@ -483,7 +492,7 @@ def test_setitem_corner2(self):
483
492
assert df .loc [1 , "title" ] == "foobar"
484
493
assert df .loc [1 , "cruft" ] == 0
485
494
486
- def test_setitem_ambig (self ):
495
+ def test_setitem_ambig (self , using_infer_string ):
487
496
# Difficulties with mixed-type data
488
497
# Created as float type
489
498
dm = DataFrame (index = range (3 ), columns = range (3 ))
@@ -499,18 +508,22 @@ def test_setitem_ambig(self):
499
508
500
509
dm [2 ] = uncoercable_series
501
510
assert len (dm .columns ) == 3
502
- assert dm [2 ].dtype == np .object_
511
+ if using_infer_string :
512
+ assert dm [2 ].dtype == "string"
513
+ else :
514
+ assert dm [2 ].dtype == np .object_
503
515
504
- def test_setitem_None (self , float_frame ):
516
+ def test_setitem_None (self , float_frame , using_infer_string ):
505
517
# GH #766
506
518
float_frame [None ] = float_frame ["A" ]
519
+ key = None if not using_infer_string else np .nan
507
520
tm .assert_series_equal (
508
521
float_frame .iloc [:, - 1 ], float_frame ["A" ], check_names = False
509
522
)
510
523
tm .assert_series_equal (
511
- float_frame .loc [:, None ], float_frame ["A" ], check_names = False
524
+ float_frame .loc [:, key ], float_frame ["A" ], check_names = False
512
525
)
513
- tm .assert_series_equal (float_frame [None ], float_frame ["A" ], check_names = False )
526
+ tm .assert_series_equal (float_frame [key ], float_frame ["A" ], check_names = False )
514
527
repr (float_frame )
515
528
516
529
def test_loc_setitem_boolean_mask_allfalse (self ):
0 commit comments