@@ -288,7 +288,9 @@ def test_setattr_column(self):
288288 df .foobar = 5
289289 assert (df .foobar == 5 ).all ()
290290
291- def test_setitem (self , float_frame , using_copy_on_write , warn_copy_on_write ):
291+ def test_setitem (
292+ self , float_frame , using_copy_on_write , warn_copy_on_write , using_infer_string
293+ ):
292294 # not sure what else to do here
293295 series = float_frame ["A" ][::2 ]
294296 float_frame ["col5" ] = series
@@ -331,7 +333,10 @@ def test_setitem(self, float_frame, using_copy_on_write, warn_copy_on_write):
331333 with pytest .raises (SettingWithCopyError , match = msg ):
332334 smaller ["col10" ] = ["1" , "2" ]
333335
334- assert smaller ["col10" ].dtype == np .object_
336+ if using_infer_string :
337+ assert smaller ["col10" ].dtype == "string"
338+ else :
339+ assert smaller ["col10" ].dtype == np .object_
335340 assert (smaller ["col10" ] == ["1" , "2" ]).all ()
336341
337342 def test_setitem2 (self ):
@@ -426,7 +431,7 @@ def test_setitem_cast(self, float_frame):
426431 float_frame ["something" ] = 2.5
427432 assert float_frame ["something" ].dtype == np .float64
428433
429- def test_setitem_corner (self , float_frame ):
434+ def test_setitem_corner (self , float_frame , using_infer_string ):
430435 # corner case
431436 df = DataFrame ({"B" : [1.0 , 2.0 , 3.0 ], "C" : ["a" , "b" , "c" ]}, index = np .arange (3 ))
432437 del df ["B" ]
@@ -463,10 +468,16 @@ def test_setitem_corner(self, float_frame):
463468 dm ["foo" ] = "bar"
464469 del dm ["foo" ]
465470 dm ["foo" ] = "bar"
466- assert dm ["foo" ].dtype == np .object_
471+ if using_infer_string :
472+ assert dm ["foo" ].dtype == "string"
473+ else :
474+ assert dm ["foo" ].dtype == np .object_
467475
468476 dm ["coercible" ] = ["1" , "2" , "3" ]
469- assert dm ["coercible" ].dtype == np .object_
477+ if using_infer_string :
478+ assert dm ["coercible" ].dtype == "string"
479+ else :
480+ assert dm ["coercible" ].dtype == np .object_
470481
471482 def test_setitem_corner2 (self ):
472483 data = {
@@ -483,7 +494,7 @@ def test_setitem_corner2(self):
483494 assert df .loc [1 , "title" ] == "foobar"
484495 assert df .loc [1 , "cruft" ] == 0
485496
486- def test_setitem_ambig (self ):
497+ def test_setitem_ambig (self , using_infer_string ):
487498 # Difficulties with mixed-type data
488499 # Created as float type
489500 dm = DataFrame (index = range (3 ), columns = range (3 ))
@@ -499,18 +510,22 @@ def test_setitem_ambig(self):
499510
500511 dm [2 ] = uncoercable_series
501512 assert len (dm .columns ) == 3
502- assert dm [2 ].dtype == np .object_
513+ if using_infer_string :
514+ assert dm [2 ].dtype == "string"
515+ else :
516+ assert dm [2 ].dtype == np .object_
503517
504- def test_setitem_None (self , float_frame ):
518+ def test_setitem_None (self , float_frame , using_infer_string ):
505519 # GH #766
506520 float_frame [None ] = float_frame ["A" ]
521+ key = None if not using_infer_string else np .nan
507522 tm .assert_series_equal (
508523 float_frame .iloc [:, - 1 ], float_frame ["A" ], check_names = False
509524 )
510525 tm .assert_series_equal (
511- float_frame .loc [:, None ], float_frame ["A" ], check_names = False
526+ float_frame .loc [:, key ], float_frame ["A" ], check_names = False
512527 )
513- tm .assert_series_equal (float_frame [None ], float_frame ["A" ], check_names = False )
528+ tm .assert_series_equal (float_frame [key ], float_frame ["A" ], check_names = False )
514529
515530 def test_loc_setitem_boolean_mask_allfalse (self ):
516531 # GH 9596
0 commit comments