@@ -1206,6 +1206,7 @@ def test_idxminmax_object_dtype(self, using_infer_string):
1206
1206
with pytest .raises (TypeError , match = msg ):
1207
1207
ser3 .idxmin (skipna = False )
1208
1208
1209
+ # TODO(infer_string) implement argmin/max for python string dtype
1209
1210
@pytest .mark .xfail (
1210
1211
using_string_dtype () and not HAS_PYARROW , reason = "TODO(infer_string)"
1211
1212
)
@@ -1431,12 +1432,14 @@ def test_mode_numerical_nan(self, dropna, expected):
1431
1432
expected = Series (expected )
1432
1433
tm .assert_series_equal (result , expected )
1433
1434
1434
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
1435
1435
@pytest .mark .parametrize (
1436
- "dropna, expected1, expected2, expected3" ,
1437
- [(True , ["b" ], ["bar" ], ["nan" ]), (False , ["b" ], [np .nan ], ["nan" ])],
1436
+ "dropna, expected1, expected2" ,
1437
+ [
1438
+ (True , ["b" ], ["bar" ]),
1439
+ (False , ["b" ], [np .nan ]),
1440
+ ],
1438
1441
)
1439
- def test_mode_str_obj (self , dropna , expected1 , expected2 , expected3 ):
1442
+ def test_mode_object (self , dropna , expected1 , expected2 ):
1440
1443
# Test string and object types.
1441
1444
data = ["a" ] * 2 + ["b" ] * 3
1442
1445
@@ -1449,30 +1452,45 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
1449
1452
1450
1453
s = Series (data , dtype = object )
1451
1454
result = s .mode (dropna )
1452
- expected2 = Series (expected2 , dtype = None if expected2 == [ "bar" ] else object )
1455
+ expected2 = Series (expected2 , dtype = object )
1453
1456
tm .assert_series_equal (result , expected2 )
1454
1457
1458
+ @pytest .mark .parametrize (
1459
+ "dropna, expected1, expected2" ,
1460
+ [
1461
+ (True , ["b" ], ["bar" ]),
1462
+ (False , ["b" ], [np .nan ]),
1463
+ ],
1464
+ )
1465
+ def test_mode_string (self , dropna , expected1 , expected2 , any_string_dtype ):
1466
+ # Test string and object types.
1467
+ data = ["a" ] * 2 + ["b" ] * 3
1468
+
1469
+ s = Series (data , dtype = any_string_dtype )
1470
+ result = s .mode (dropna )
1471
+ expected1 = Series (expected1 , dtype = any_string_dtype )
1472
+ tm .assert_series_equal (result , expected1 )
1473
+
1455
1474
data = ["foo" , "bar" , "bar" , np .nan , np .nan , np .nan ]
1456
1475
1457
- s = Series (data , dtype = object ). astype ( str )
1476
+ s = Series (data , dtype = any_string_dtype )
1458
1477
result = s .mode (dropna )
1459
- expected3 = Series (expected3 )
1460
- tm .assert_series_equal (result , expected3 )
1478
+ expected2 = Series (expected2 , dtype = any_string_dtype )
1479
+ tm .assert_series_equal (result , expected2 )
1461
1480
1462
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
1463
1481
@pytest .mark .parametrize (
1464
1482
"dropna, expected1, expected2" ,
1465
1483
[(True , ["foo" ], ["foo" ]), (False , ["foo" ], [np .nan ])],
1466
1484
)
1467
1485
def test_mode_mixeddtype (self , dropna , expected1 , expected2 ):
1468
1486
s = Series ([1 , "foo" , "foo" ])
1469
1487
result = s .mode (dropna )
1470
- expected = Series (expected1 )
1488
+ expected = Series (expected1 , dtype = object )
1471
1489
tm .assert_series_equal (result , expected )
1472
1490
1473
1491
s = Series ([1 , "foo" , "foo" , np .nan , np .nan , np .nan ])
1474
1492
result = s .mode (dropna )
1475
- expected = Series (expected2 , dtype = None if expected2 == [ "foo" ] else object )
1493
+ expected = Series (expected2 , dtype = object )
1476
1494
tm .assert_series_equal (result , expected )
1477
1495
1478
1496
@pytest .mark .parametrize (
@@ -1597,12 +1615,11 @@ def test_mode_intoverflow(self, dropna, expected1, expected2):
1597
1615
expected2 = Series (expected2 , dtype = np .uint64 )
1598
1616
tm .assert_series_equal (result , expected2 )
1599
1617
1600
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
1601
1618
def test_mode_sortwarning (self ):
1602
1619
# Check for the warning that is raised when the mode
1603
1620
# results cannot be sorted
1604
1621
1605
- expected = Series (["foo" , np .nan ])
1622
+ expected = Series (["foo" , np .nan ], dtype = object )
1606
1623
s = Series ([1 , "foo" , "foo" , np .nan , np .nan ])
1607
1624
1608
1625
with tm .assert_produces_warning (UserWarning , match = "Unable to sort modes" ):
0 commit comments