Skip to content

Commit 4651ddb

Browse files
TST (string dtype): update tests/reductions tests (#60133)
1 parent 2fdb16b commit 4651ddb

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

pandas/tests/reductions/test_reductions.py

+30-13
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ def test_idxminmax_object_dtype(self, using_infer_string):
12061206
with pytest.raises(TypeError, match=msg):
12071207
ser3.idxmin(skipna=False)
12081208

1209+
# TODO(infer_string) implement argmin/max for python string dtype
12091210
@pytest.mark.xfail(
12101211
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
12111212
)
@@ -1431,12 +1432,14 @@ def test_mode_numerical_nan(self, dropna, expected):
14311432
expected = Series(expected)
14321433
tm.assert_series_equal(result, expected)
14331434

1434-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
14351435
@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+
],
14381441
)
1439-
def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
1442+
def test_mode_object(self, dropna, expected1, expected2):
14401443
# Test string and object types.
14411444
data = ["a"] * 2 + ["b"] * 3
14421445

@@ -1449,30 +1452,45 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
14491452

14501453
s = Series(data, dtype=object)
14511454
result = s.mode(dropna)
1452-
expected2 = Series(expected2, dtype=None if expected2 == ["bar"] else object)
1455+
expected2 = Series(expected2, dtype=object)
14531456
tm.assert_series_equal(result, expected2)
14541457

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+
14551474
data = ["foo", "bar", "bar", np.nan, np.nan, np.nan]
14561475

1457-
s = Series(data, dtype=object).astype(str)
1476+
s = Series(data, dtype=any_string_dtype)
14581477
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)
14611480

1462-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
14631481
@pytest.mark.parametrize(
14641482
"dropna, expected1, expected2",
14651483
[(True, ["foo"], ["foo"]), (False, ["foo"], [np.nan])],
14661484
)
14671485
def test_mode_mixeddtype(self, dropna, expected1, expected2):
14681486
s = Series([1, "foo", "foo"])
14691487
result = s.mode(dropna)
1470-
expected = Series(expected1)
1488+
expected = Series(expected1, dtype=object)
14711489
tm.assert_series_equal(result, expected)
14721490

14731491
s = Series([1, "foo", "foo", np.nan, np.nan, np.nan])
14741492
result = s.mode(dropna)
1475-
expected = Series(expected2, dtype=None if expected2 == ["foo"] else object)
1493+
expected = Series(expected2, dtype=object)
14761494
tm.assert_series_equal(result, expected)
14771495

14781496
@pytest.mark.parametrize(
@@ -1597,12 +1615,11 @@ def test_mode_intoverflow(self, dropna, expected1, expected2):
15971615
expected2 = Series(expected2, dtype=np.uint64)
15981616
tm.assert_series_equal(result, expected2)
15991617

1600-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
16011618
def test_mode_sortwarning(self):
16021619
# Check for the warning that is raised when the mode
16031620
# results cannot be sorted
16041621

1605-
expected = Series(["foo", np.nan])
1622+
expected = Series(["foo", np.nan], dtype=object)
16061623
s = Series([1, "foo", "foo", np.nan, np.nan])
16071624

16081625
with tm.assert_produces_warning(UserWarning, match="Unable to sort modes"):

0 commit comments

Comments
 (0)