Skip to content

Commit 72f06ef

Browse files
authored
TST: Remove some xfails in groupby tests (#52065)
1 parent b5aec87 commit 72f06ef

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

pandas/tests/groupby/test_api_consistency.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import inspect
66

7-
import pytest
8-
97
from pandas import (
108
DataFrame,
119
Series,
@@ -16,16 +14,13 @@
1614
)
1715

1816

19-
def test_frame_consistency(request, groupby_func):
17+
def test_frame_consistency(groupby_func):
2018
# GH#48028
2119
if groupby_func in ("first", "last"):
22-
msg = "first and last are entirely different between frame and groupby"
23-
request.node.add_marker(pytest.mark.xfail(reason=msg))
24-
if groupby_func in ("cumcount",):
25-
msg = "DataFrame has no such method"
26-
request.node.add_marker(pytest.mark.xfail(reason=msg))
20+
# first and last are entirely different between frame and groupby
21+
return
2722

28-
if groupby_func == "ngroup":
23+
if groupby_func in ("cumcount", "ngroup"):
2924
assert not hasattr(DataFrame, groupby_func)
3025
return
3126

@@ -82,13 +77,10 @@ def test_frame_consistency(request, groupby_func):
8277
def test_series_consistency(request, groupby_func):
8378
# GH#48028
8479
if groupby_func in ("first", "last"):
85-
msg = "first and last are entirely different between Series and groupby"
86-
request.node.add_marker(pytest.mark.xfail(reason=msg))
87-
if groupby_func in ("cumcount", "corrwith"):
88-
msg = "Series has no such method"
89-
request.node.add_marker(pytest.mark.xfail(reason=msg))
80+
# first and last are entirely different between Series and groupby
81+
return
9082

91-
if groupby_func == "ngroup":
83+
if groupby_func in ("cumcount", "corrwith", "ngroup"):
9284
assert not hasattr(Series, groupby_func)
9385
return
9486

pandas/tests/groupby/test_categorical.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1340,17 +1340,11 @@ def test_get_nonexistent_category():
13401340
)
13411341

13421342

1343-
def test_series_groupby_on_2_categoricals_unobserved(reduction_func, observed, request):
1343+
def test_series_groupby_on_2_categoricals_unobserved(reduction_func, observed):
13441344
# GH 17605
13451345
if reduction_func == "ngroup":
13461346
pytest.skip("ngroup is not truly a reduction")
13471347

1348-
if reduction_func == "corrwith": # GH 32293
1349-
mark = pytest.mark.xfail(
1350-
reason="TODO: implemented SeriesGroupBy.corrwith. See GH 32293"
1351-
)
1352-
request.node.add_marker(mark)
1353-
13541348
df = DataFrame(
13551349
{
13561350
"cat_1": Categorical(list("AABB"), categories=list("ABCD")),
@@ -1363,6 +1357,12 @@ def test_series_groupby_on_2_categoricals_unobserved(reduction_func, observed, r
13631357
expected_length = 4 if observed else 16
13641358

13651359
series_groupby = df.groupby(["cat_1", "cat_2"], observed=observed)["value"]
1360+
1361+
if reduction_func == "corrwith":
1362+
# TODO: implemented SeriesGroupBy.corrwith. See GH 32293
1363+
assert not hasattr(series_groupby, reduction_func)
1364+
return
1365+
13661366
agg = getattr(series_groupby, reduction_func)
13671367
result = agg(*args)
13681368

pandas/tests/groupby/test_function.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1483,14 +1483,16 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys):
14831483
@pytest.mark.parametrize("dtype", [bool, int, float, object])
14841484
def test_deprecate_numeric_only_series(dtype, groupby_func, request):
14851485
# GH#46560
1486-
if groupby_func == "corrwith":
1487-
msg = "corrwith is not implemented on SeriesGroupBy"
1488-
request.node.add_marker(pytest.mark.xfail(reason=msg))
1489-
14901486
grouper = [0, 0, 1]
14911487

14921488
ser = Series([1, 0, 0], dtype=dtype)
14931489
gb = ser.groupby(grouper)
1490+
1491+
if groupby_func == "corrwith":
1492+
# corrwith is not implemented on SeriesGroupBy
1493+
assert not hasattr(gb, groupby_func)
1494+
return
1495+
14941496
method = getattr(gb, groupby_func)
14951497

14961498
expected_ser = Series([1, 0, 0])

pandas/tests/groupby/transform/test_transform.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1125,9 +1125,9 @@ def test_transform_agg_by_name(request, reduction_func, frame_or_series):
11251125
g = obj.groupby(np.repeat([0, 1], 3))
11261126

11271127
if func == "corrwith" and isinstance(obj, Series): # GH#32293
1128-
request.node.add_marker(
1129-
pytest.mark.xfail(reason="TODO: implement SeriesGroupBy.corrwith")
1130-
)
1128+
# TODO: implement SeriesGroupBy.corrwith
1129+
assert not hasattr(g, func)
1130+
return
11311131

11321132
args = get_groupby_method_args(reduction_func, obj)
11331133
result = g.transform(func, *args)
@@ -1389,16 +1389,16 @@ def test_null_group_str_transformer(request, dropna, transformation_func):
13891389

13901390

13911391
def test_null_group_str_reducer_series(request, dropna, reduction_func):
1392-
# GH 17093
1393-
if reduction_func == "corrwith":
1394-
msg = "corrwith not implemented for SeriesGroupBy"
1395-
request.node.add_marker(pytest.mark.xfail(reason=msg))
1396-
13971392
# GH 17093
13981393
index = [1, 2, 3, 4] # test transform preserves non-standard index
13991394
ser = Series([1, 2, 2, 3], index=index)
14001395
gb = ser.groupby([1, 1, np.nan, np.nan], dropna=dropna)
14011396

1397+
if reduction_func == "corrwith":
1398+
# corrwith not implemented for SeriesGroupBy
1399+
assert not hasattr(gb, reduction_func)
1400+
return
1401+
14021402
args = get_groupby_method_args(reduction_func, ser)
14031403

14041404
# Manually handle reducers that don't fit the generic pattern

0 commit comments

Comments
 (0)