Skip to content

TST: clean up some groupby xfails #51257

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 2 commits into from
Feb 9, 2023
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
30 changes: 20 additions & 10 deletions pandas/tests/groupby/test_api_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ def test_frame_consistency(request, groupby_func):
if groupby_func in ("first", "last"):
msg = "first and last are entirely different between frame and groupby"
request.node.add_marker(pytest.mark.xfail(reason=msg))
if groupby_func in ("nth", "cumcount", "ngroup"):
if groupby_func in ("cumcount",):
msg = "DataFrame has no such method"
request.node.add_marker(pytest.mark.xfail(reason=msg))
if groupby_func in ("size",):
msg = "Method is a property"
request.node.add_marker(pytest.mark.xfail(reason=msg))

if groupby_func == "ngroup":
assert not hasattr(DataFrame, groupby_func)
return

frame_method = getattr(DataFrame, groupby_func)
gb_method = getattr(DataFrameGroupBy, groupby_func)
result = set(inspect.signature(gb_method).parameters)
expected = set(inspect.signature(frame_method).parameters)
if groupby_func == "size":
# "size" is a method on GroupBy but property on DataFrame:
expected = {"self"}
else:
expected = set(inspect.signature(frame_method).parameters)

# Exclude certain arguments from result and expected depending on the operation
# Some of these may be purposeful inconsistencies between the APIs
Expand Down Expand Up @@ -79,17 +84,22 @@ def test_series_consistency(request, groupby_func):
if groupby_func in ("first", "last"):
msg = "first and last are entirely different between Series and groupby"
request.node.add_marker(pytest.mark.xfail(reason=msg))
if groupby_func in ("nth", "cumcount", "ngroup", "corrwith"):
if groupby_func in ("cumcount", "corrwith"):
msg = "Series has no such method"
request.node.add_marker(pytest.mark.xfail(reason=msg))
if groupby_func in ("size",):
msg = "Method is a property"
request.node.add_marker(pytest.mark.xfail(reason=msg))

if groupby_func == "ngroup":
assert not hasattr(Series, groupby_func)
return

series_method = getattr(Series, groupby_func)
gb_method = getattr(SeriesGroupBy, groupby_func)
result = set(inspect.signature(gb_method).parameters)
expected = set(inspect.signature(series_method).parameters)
if groupby_func == "size":
# "size" is a method on GroupBy but property on Series
expected = {"self"}
else:
expected = set(inspect.signature(series_method).parameters)

# Exclude certain arguments from result and expected depending on the operation
# Some of these may be purposeful inconsistencies between the APIs
Expand Down