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