From 83be00e5b058fbd9d58cce85697f7bae8551d61d Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 18 Mar 2023 10:48:29 -0400 Subject: [PATCH] TST: Remove some xfails in groupby tests --- pandas/tests/groupby/test_api_consistency.py | 22 ++++++------------- pandas/tests/groupby/test_categorical.py | 14 ++++++------ pandas/tests/groupby/test_function.py | 10 +++++---- .../tests/groupby/transform/test_transform.py | 16 +++++++------- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/pandas/tests/groupby/test_api_consistency.py b/pandas/tests/groupby/test_api_consistency.py index d62ee3593cd44..ac5d0d23c7631 100644 --- a/pandas/tests/groupby/test_api_consistency.py +++ b/pandas/tests/groupby/test_api_consistency.py @@ -4,8 +4,6 @@ import inspect -import pytest - from pandas import ( DataFrame, Series, @@ -16,16 +14,13 @@ ) -def test_frame_consistency(request, groupby_func): +def test_frame_consistency(groupby_func): # GH#48028 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 ("cumcount",): - msg = "DataFrame has no such method" - request.node.add_marker(pytest.mark.xfail(reason=msg)) + # first and last are entirely different between frame and groupby + return - if groupby_func == "ngroup": + if groupby_func in ("cumcount", "ngroup"): assert not hasattr(DataFrame, groupby_func) return @@ -82,13 +77,10 @@ def test_frame_consistency(request, groupby_func): def test_series_consistency(request, groupby_func): # GH#48028 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 ("cumcount", "corrwith"): - msg = "Series has no such method" - request.node.add_marker(pytest.mark.xfail(reason=msg)) + # first and last are entirely different between Series and groupby + return - if groupby_func == "ngroup": + if groupby_func in ("cumcount", "corrwith", "ngroup"): assert not hasattr(Series, groupby_func) return diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index e4dd07f790f47..5ecb765e5861e 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -1340,17 +1340,11 @@ def test_get_nonexistent_category(): ) -def test_series_groupby_on_2_categoricals_unobserved(reduction_func, observed, request): +def test_series_groupby_on_2_categoricals_unobserved(reduction_func, observed): # GH 17605 if reduction_func == "ngroup": pytest.skip("ngroup is not truly a reduction") - if reduction_func == "corrwith": # GH 32293 - mark = pytest.mark.xfail( - reason="TODO: implemented SeriesGroupBy.corrwith. See GH 32293" - ) - request.node.add_marker(mark) - df = DataFrame( { "cat_1": Categorical(list("AABB"), categories=list("ABCD")), @@ -1363,6 +1357,12 @@ def test_series_groupby_on_2_categoricals_unobserved(reduction_func, observed, r expected_length = 4 if observed else 16 series_groupby = df.groupby(["cat_1", "cat_2"], observed=observed)["value"] + + if reduction_func == "corrwith": + # TODO: implemented SeriesGroupBy.corrwith. See GH 32293 + assert not hasattr(series_groupby, reduction_func) + return + agg = getattr(series_groupby, reduction_func) result = agg(*args) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 9ca2695e0d091..69f68a8e95810 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -1483,14 +1483,16 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys): @pytest.mark.parametrize("dtype", [bool, int, float, object]) def test_deprecate_numeric_only_series(dtype, groupby_func, request): # GH#46560 - if groupby_func == "corrwith": - msg = "corrwith is not implemented on SeriesGroupBy" - request.node.add_marker(pytest.mark.xfail(reason=msg)) - grouper = [0, 0, 1] ser = Series([1, 0, 0], dtype=dtype) gb = ser.groupby(grouper) + + if groupby_func == "corrwith": + # corrwith is not implemented on SeriesGroupBy + assert not hasattr(gb, groupby_func) + return + method = getattr(gb, groupby_func) expected_ser = Series([1, 0, 0]) diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index d6d0b03a65ebb..d7dc2d8937467 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -1125,9 +1125,9 @@ def test_transform_agg_by_name(request, reduction_func, frame_or_series): g = obj.groupby(np.repeat([0, 1], 3)) if func == "corrwith" and isinstance(obj, Series): # GH#32293 - request.node.add_marker( - pytest.mark.xfail(reason="TODO: implement SeriesGroupBy.corrwith") - ) + # TODO: implement SeriesGroupBy.corrwith + assert not hasattr(g, func) + return args = get_groupby_method_args(reduction_func, obj) result = g.transform(func, *args) @@ -1389,16 +1389,16 @@ def test_null_group_str_transformer(request, dropna, transformation_func): def test_null_group_str_reducer_series(request, dropna, reduction_func): - # GH 17093 - if reduction_func == "corrwith": - msg = "corrwith not implemented for SeriesGroupBy" - request.node.add_marker(pytest.mark.xfail(reason=msg)) - # GH 17093 index = [1, 2, 3, 4] # test transform preserves non-standard index ser = Series([1, 2, 2, 3], index=index) gb = ser.groupby([1, 1, np.nan, np.nan], dropna=dropna) + if reduction_func == "corrwith": + # corrwith not implemented for SeriesGroupBy + assert not hasattr(gb, reduction_func) + return + args = get_groupby_method_args(reduction_func, ser) # Manually handle reducers that don't fit the generic pattern