Skip to content

TST (string dtype): update tests/reductions tests #60133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ def test_idxminmax_object_dtype(self, using_infer_string):
with pytest.raises(TypeError, match=msg):
ser3.idxmin(skipna=False)

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

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
@pytest.mark.parametrize(
"dropna, expected1, expected2, expected3",
[(True, ["b"], ["bar"], ["nan"]), (False, ["b"], [np.nan], ["nan"])],
"dropna, expected1, expected2",
[
(True, ["b"], ["bar"]),
(False, ["b"], [np.nan]),
],
)
def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
def test_mode_object(self, dropna, expected1, expected2):
# Test string and object types.
data = ["a"] * 2 + ["b"] * 3

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

s = Series(data, dtype=object)
result = s.mode(dropna)
expected2 = Series(expected2, dtype=None if expected2 == ["bar"] else object)
expected2 = Series(expected2, dtype=object)
tm.assert_series_equal(result, expected2)

@pytest.mark.parametrize(
"dropna, expected1, expected2",
[
(True, ["b"], ["bar"]),
(False, ["b"], [np.nan]),
],
)
def test_mode_string(self, dropna, expected1, expected2, any_string_dtype):
# Test string and object types.
data = ["a"] * 2 + ["b"] * 3

s = Series(data, dtype=any_string_dtype)
result = s.mode(dropna)
expected1 = Series(expected1, dtype=any_string_dtype)
tm.assert_series_equal(result, expected1)

data = ["foo", "bar", "bar", np.nan, np.nan, np.nan]

s = Series(data, dtype=object).astype(str)
s = Series(data, dtype=any_string_dtype)
result = s.mode(dropna)
expected3 = Series(expected3)
tm.assert_series_equal(result, expected3)
expected2 = Series(expected2, dtype=any_string_dtype)
tm.assert_series_equal(result, expected2)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
@pytest.mark.parametrize(
"dropna, expected1, expected2",
[(True, ["foo"], ["foo"]), (False, ["foo"], [np.nan])],
)
def test_mode_mixeddtype(self, dropna, expected1, expected2):
s = Series([1, "foo", "foo"])
result = s.mode(dropna)
expected = Series(expected1)
expected = Series(expected1, dtype=object)
tm.assert_series_equal(result, expected)

s = Series([1, "foo", "foo", np.nan, np.nan, np.nan])
result = s.mode(dropna)
expected = Series(expected2, dtype=None if expected2 == ["foo"] else object)
expected = Series(expected2, dtype=object)
tm.assert_series_equal(result, expected)

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

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

expected = Series(["foo", np.nan])
expected = Series(["foo", np.nan], dtype=object)
s = Series([1, "foo", "foo", np.nan, np.nan])

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