Skip to content

Commit 076e1d9

Browse files
authored
TST: clean up some groupby xfails (#51257)
1 parent 8f3c1db commit 076e1d9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pandas/tests/groupby/test_api_consistency.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ def test_frame_consistency(request, groupby_func):
2121
if groupby_func in ("first", "last"):
2222
msg = "first and last are entirely different between frame and groupby"
2323
request.node.add_marker(pytest.mark.xfail(reason=msg))
24-
if groupby_func in ("nth", "cumcount", "ngroup"):
24+
if groupby_func in ("cumcount",):
2525
msg = "DataFrame has no such method"
2626
request.node.add_marker(pytest.mark.xfail(reason=msg))
27-
if groupby_func in ("size",):
28-
msg = "Method is a property"
29-
request.node.add_marker(pytest.mark.xfail(reason=msg))
27+
28+
if groupby_func == "ngroup":
29+
assert not hasattr(DataFrame, groupby_func)
30+
return
3031

3132
frame_method = getattr(DataFrame, groupby_func)
3233
gb_method = getattr(DataFrameGroupBy, groupby_func)
3334
result = set(inspect.signature(gb_method).parameters)
34-
expected = set(inspect.signature(frame_method).parameters)
35+
if groupby_func == "size":
36+
# "size" is a method on GroupBy but property on DataFrame:
37+
expected = {"self"}
38+
else:
39+
expected = set(inspect.signature(frame_method).parameters)
3540

3641
# Exclude certain arguments from result and expected depending on the operation
3742
# Some of these may be purposeful inconsistencies between the APIs
@@ -79,17 +84,22 @@ def test_series_consistency(request, groupby_func):
7984
if groupby_func in ("first", "last"):
8085
msg = "first and last are entirely different between Series and groupby"
8186
request.node.add_marker(pytest.mark.xfail(reason=msg))
82-
if groupby_func in ("nth", "cumcount", "ngroup", "corrwith"):
87+
if groupby_func in ("cumcount", "corrwith"):
8388
msg = "Series has no such method"
8489
request.node.add_marker(pytest.mark.xfail(reason=msg))
85-
if groupby_func in ("size",):
86-
msg = "Method is a property"
87-
request.node.add_marker(pytest.mark.xfail(reason=msg))
90+
91+
if groupby_func == "ngroup":
92+
assert not hasattr(Series, groupby_func)
93+
return
8894

8995
series_method = getattr(Series, groupby_func)
9096
gb_method = getattr(SeriesGroupBy, groupby_func)
9197
result = set(inspect.signature(gb_method).parameters)
92-
expected = set(inspect.signature(series_method).parameters)
98+
if groupby_func == "size":
99+
# "size" is a method on GroupBy but property on Series
100+
expected = {"self"}
101+
else:
102+
expected = set(inspect.signature(series_method).parameters)
93103

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

0 commit comments

Comments
 (0)