diff --git a/pandas/tests/groupby/test_api_consistency.py b/pandas/tests/groupby/test_api_consistency.py index bd29f29719494..d62ee3593cd44 100644 --- a/pandas/tests/groupby/test_api_consistency.py +++ b/pandas/tests/groupby/test_api_consistency.py @@ -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 @@ -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