Skip to content

TST: fix groupby xfails #41387

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
merged 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,7 @@ def test_pivot_table_values_key_error():
)
def test_empty_groupby(columns, keys, values, method, op, request):
# GH8093 & GH26411
override_dtype = None

if isinstance(values, Categorical) and len(keys) == 1 and method == "apply":
mark = pytest.mark.xfail(raises=TypeError, match="'str' object is not callable")
Expand Down Expand Up @@ -1784,12 +1785,9 @@ def test_empty_groupby(columns, keys, values, method, op, request):
and op in ["sum", "prod"]
and method != "apply"
):
mark = pytest.mark.xfail(
raises=AssertionError, match="(DataFrame|Series) are different"
)
request.node.add_marker(mark)
# We expect to get Int64 back for these
override_dtype = "Int64"

override_dtype = None
if isinstance(values[0], bool) and op in ("prod", "sum") and method != "apply":
# sum/product of bools is an integer
override_dtype = "int64"
Expand Down
24 changes: 17 additions & 7 deletions pandas/tests/groupby/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
concat,
)
import pandas._testing as tm
from pandas.core.base import DataError


def test_rank_apply():
Expand Down Expand Up @@ -462,21 +461,32 @@ def test_rank_avg_even_vals(dtype, upper):
tm.assert_frame_equal(result, exp_df)


@pytest.mark.xfail(reason="Works now, needs tests")
@pytest.mark.parametrize("ties_method", ["average", "min", "max", "first", "dense"])
@pytest.mark.parametrize("ascending", [True, False])
@pytest.mark.parametrize("na_option", ["keep", "top", "bottom"])
@pytest.mark.parametrize("pct", [True, False])
@pytest.mark.parametrize(
"vals", [["bar", "bar", "foo", "bar", "baz"], ["bar", np.nan, "foo", np.nan, "baz"]]
)
def test_rank_object_raises(ties_method, ascending, na_option, pct, vals):
def test_rank_object_dtype(ties_method, ascending, na_option, pct, vals):
df = DataFrame({"key": ["foo"] * 5, "val": vals})
mask = df["val"].isna()

with pytest.raises(DataError, match="No numeric types to aggregate"):
df.groupby("key").rank(
method=ties_method, ascending=ascending, na_option=na_option, pct=pct
)
gb = df.groupby("key")
res = gb.rank(method=ties_method, ascending=ascending, na_option=na_option, pct=pct)

# construct our expected by using numeric values with the same ordering
if mask.any():
df2 = DataFrame({"key": ["foo"] * 5, "val": [0, np.nan, 2, np.nan, 1]})
else:
df2 = DataFrame({"key": ["foo"] * 5, "val": [0, 0, 2, 0, 1]})

gb2 = df2.groupby("key")
alt = gb2.rank(
method=ties_method, ascending=ascending, na_option=na_option, pct=pct
)

tm.assert_frame_equal(res, alt)


@pytest.mark.parametrize("na_option", [True, "bad", 1])
Expand Down