Skip to content

Commit 018a38e

Browse files
Backport PR #60133 on branch 2.3.x (TST (string dtype): update tests/reductions tests) (#60158)
Backport PR #60133: TST (string dtype): update tests/reductions tests Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 4f189a4 commit 018a38e

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
@@ -1246,6 +1246,7 @@ def test_idxminmax_object_dtype(self, using_infer_string):
12461246
with pytest.raises(TypeError, match=msg):
12471247
ser3.idxmin(skipna=False)
12481248

1249+
# TODO(infer_string) implement argmin/max for python string dtype
12491250
@pytest.mark.xfail(
12501251
using_string_dtype() and not HAS_PYARROW, reason="TODO(infer_string)"
12511252
)
@@ -1485,12 +1486,14 @@ def test_mode_numerical_nan(self, dropna, expected):
14851486
expected = Series(expected)
14861487
tm.assert_series_equal(result, expected)
14871488

1488-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
14891489
@pytest.mark.parametrize(
1490-
"dropna, expected1, expected2, expected3",
1491-
[(True, ["b"], ["bar"], ["nan"]), (False, ["b"], [np.nan], ["nan"])],
1490+
"dropna, expected1, expected2",
1491+
[
1492+
(True, ["b"], ["bar"]),
1493+
(False, ["b"], [np.nan]),
1494+
],
14921495
)
1493-
def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
1496+
def test_mode_object(self, dropna, expected1, expected2):
14941497
# Test string and object types.
14951498
data = ["a"] * 2 + ["b"] * 3
14961499

@@ -1503,30 +1506,45 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
15031506

15041507
s = Series(data, dtype=object)
15051508
result = s.mode(dropna)
1506-
expected2 = Series(expected2, dtype=None if expected2 == ["bar"] else object)
1509+
expected2 = Series(expected2, dtype=object)
15071510
tm.assert_series_equal(result, expected2)
15081511

1512+
@pytest.mark.parametrize(
1513+
"dropna, expected1, expected2",
1514+
[
1515+
(True, ["b"], ["bar"]),
1516+
(False, ["b"], [np.nan]),
1517+
],
1518+
)
1519+
def test_mode_string(self, dropna, expected1, expected2, any_string_dtype):
1520+
# Test string and object types.
1521+
data = ["a"] * 2 + ["b"] * 3
1522+
1523+
s = Series(data, dtype=any_string_dtype)
1524+
result = s.mode(dropna)
1525+
expected1 = Series(expected1, dtype=any_string_dtype)
1526+
tm.assert_series_equal(result, expected1)
1527+
15091528
data = ["foo", "bar", "bar", np.nan, np.nan, np.nan]
15101529

1511-
s = Series(data, dtype=object).astype(str)
1530+
s = Series(data, dtype=any_string_dtype)
15121531
result = s.mode(dropna)
1513-
expected3 = Series(expected3)
1514-
tm.assert_series_equal(result, expected3)
1532+
expected2 = Series(expected2, dtype=any_string_dtype)
1533+
tm.assert_series_equal(result, expected2)
15151534

1516-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
15171535
@pytest.mark.parametrize(
15181536
"dropna, expected1, expected2",
15191537
[(True, ["foo"], ["foo"]), (False, ["foo"], [np.nan])],
15201538
)
15211539
def test_mode_mixeddtype(self, dropna, expected1, expected2):
15221540
s = Series([1, "foo", "foo"])
15231541
result = s.mode(dropna)
1524-
expected = Series(expected1)
1542+
expected = Series(expected1, dtype=object)
15251543
tm.assert_series_equal(result, expected)
15261544

15271545
s = Series([1, "foo", "foo", np.nan, np.nan, np.nan])
15281546
result = s.mode(dropna)
1529-
expected = Series(expected2, dtype=None if expected2 == ["foo"] else object)
1547+
expected = Series(expected2, dtype=object)
15301548
tm.assert_series_equal(result, expected)
15311549

15321550
@pytest.mark.parametrize(
@@ -1651,12 +1669,11 @@ def test_mode_intoverflow(self, dropna, expected1, expected2):
16511669
expected2 = Series(expected2, dtype=np.uint64)
16521670
tm.assert_series_equal(result, expected2)
16531671

1654-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
16551672
def test_mode_sortwarning(self):
16561673
# Check for the warning that is raised when the mode
16571674
# results cannot be sorted
16581675

1659-
expected = Series(["foo", np.nan])
1676+
expected = Series(["foo", np.nan], dtype=object)
16601677
s = Series([1, "foo", "foo", np.nan, np.nan])
16611678

16621679
with tm.assert_produces_warning(UserWarning):

0 commit comments

Comments
 (0)