Skip to content

TST: Use stronger assertion in test_regression_allowlist_methods #49755

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
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
24 changes: 14 additions & 10 deletions pandas/tests/groupby/test_allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ def df_letters():


@pytest.fixture
def raw_frame(multiindex_dataframe_random_data):
df = multiindex_dataframe_random_data
df.iloc[1, [1, 2]] = np.nan
df.iloc[7, [0, 1]] = np.nan
return df
def raw_frame():
return DataFrame([0])


@pytest.mark.parametrize("op", AGG_FUNCTIONS)
Expand All @@ -84,14 +81,21 @@ def test_regression_allowlist_methods(raw_frame, op, axis, skipna, sort):
frame = raw_frame.T

if op in AGG_FUNCTIONS_WITH_SKIPNA:
grouped = frame.groupby("first", axis=axis, sort=sort)
grouped = frame.groupby(level=0, axis=axis, sort=sort)
result = getattr(grouped, op)(skipna=skipna)
expected = frame.groupby(level=0).apply(
lambda h: getattr(h, op)(axis=axis, skipna=skipna)
)
if sort:
expected = expected.sort_index(axis=axis)
tm.assert_frame_equal(result, expected)
else:
grouped = frame.groupby("first", axis=axis, sort=sort)
grouped = frame.groupby(level=0, axis=axis, sort=sort)
result = getattr(grouped, op)()
# Previously compared to frame.op(level=...), but level removed in 2.0
# TODO(GH 49629): Assert something better
assert isinstance(result, DataFrame)
expected = frame.groupby(level=0).apply(lambda h: getattr(h, op)(axis=axis))
if sort:
expected = expected.sort_index(axis=axis)
tm.assert_frame_equal(result, expected)


def test_groupby_blocklist(df_letters):
Expand Down