Skip to content

Commit

Permalink
Backport PR pandas-dev#60133: TST (string dtype): update tests/reduct…
Browse files Browse the repository at this point in the history
…ions tests
  • Loading branch information
jorisvandenbossche authored and meeseeksmachine committed Oct 31, 2024
1 parent 4f189a4 commit 59359d5
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,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 @@ -1485,12 +1486,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 @@ -1503,30 +1506,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 @@ -1651,12 +1669,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):
Expand Down

0 comments on commit 59359d5

Please sign in to comment.