Skip to content

Commit b0192c7

Browse files
authored
CLN: Remove deprecations of groupby.fillna in tests (#60565)
1 parent 9501650 commit b0192c7

7 files changed

+18
-69
lines changed

pandas/tests/groupby/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def get_groupby_method_args(name, obj):
22
"""
33
Get required arguments for a groupby method.
44
5-
When parametrizing a test over groupby methods (e.g. "sum", "mean", "fillna"),
5+
When parametrizing a test over groupby methods (e.g. "sum", "mean"),
66
it is often the case that arguments are required for certain methods.
77
88
Parameters
@@ -16,7 +16,7 @@ def get_groupby_method_args(name, obj):
1616
-------
1717
A tuple of required arguments for the method.
1818
"""
19-
if name in ("nth", "fillna", "take"):
19+
if name in ("nth", "take"):
2020
return (0,)
2121
if name == "quantile":
2222
return (0.5,)

pandas/tests/groupby/test_categorical.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1963,10 +1963,7 @@ def test_category_order_transformer(
19631963
df = df.set_index(keys)
19641964
args = get_groupby_method_args(transformation_func, df)
19651965
gb = df.groupby(keys, as_index=as_index, sort=sort, observed=observed)
1966-
warn = FutureWarning if transformation_func == "fillna" else None
1967-
msg = "DataFrameGroupBy.fillna is deprecated"
1968-
with tm.assert_produces_warning(warn, match=msg):
1969-
op_result = getattr(gb, transformation_func)(*args)
1966+
op_result = getattr(gb, transformation_func)(*args)
19701967
result = op_result.index.get_level_values("a").categories
19711968
expected = Index([1, 4, 3, 2])
19721969
tm.assert_index_equal(result, expected)

pandas/tests/groupby/test_groupby.py

+4-26
Original file line numberDiff line numberDiff line change
@@ -2098,36 +2098,14 @@ def test_group_on_empty_multiindex(transformation_func, request):
20982098
df["col_3"] = df["col_3"].astype(int)
20992099
df["col_4"] = df["col_4"].astype(int)
21002100
df = df.set_index(["col_1", "col_2"])
2101-
if transformation_func == "fillna":
2102-
args = ("ffill",)
2103-
else:
2104-
args = ()
2105-
warn = FutureWarning if transformation_func == "fillna" else None
2106-
warn_msg = "DataFrameGroupBy.fillna is deprecated"
2107-
with tm.assert_produces_warning(warn, match=warn_msg):
2108-
result = df.iloc[:0].groupby(["col_1"]).transform(transformation_func, *args)
2109-
with tm.assert_produces_warning(warn, match=warn_msg):
2110-
expected = df.groupby(["col_1"]).transform(transformation_func, *args).iloc[:0]
2101+
result = df.iloc[:0].groupby(["col_1"]).transform(transformation_func)
2102+
expected = df.groupby(["col_1"]).transform(transformation_func).iloc[:0]
21112103
if transformation_func in ("diff", "shift"):
21122104
expected = expected.astype(int)
21132105
tm.assert_equal(result, expected)
21142106

2115-
warn_msg = "SeriesGroupBy.fillna is deprecated"
2116-
with tm.assert_produces_warning(warn, match=warn_msg):
2117-
result = (
2118-
df["col_3"]
2119-
.iloc[:0]
2120-
.groupby(["col_1"])
2121-
.transform(transformation_func, *args)
2122-
)
2123-
warn_msg = "SeriesGroupBy.fillna is deprecated"
2124-
with tm.assert_produces_warning(warn, match=warn_msg):
2125-
expected = (
2126-
df["col_3"]
2127-
.groupby(["col_1"])
2128-
.transform(transformation_func, *args)
2129-
.iloc[:0]
2130-
)
2107+
result = df["col_3"].iloc[:0].groupby(["col_1"]).transform(transformation_func)
2108+
expected = df["col_3"].groupby(["col_1"]).transform(transformation_func).iloc[:0]
21312109
if transformation_func in ("diff", "shift"):
21322110
expected = expected.astype(int)
21332111
tm.assert_equal(result, expected)

pandas/tests/groupby/test_groupby_subclass.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def test_groupby_preserves_subclass(obj, groupby_func):
3636

3737
args = get_groupby_method_args(groupby_func, obj)
3838

39-
warn = FutureWarning if groupby_func == "fillna" else None
40-
msg = f"{type(grouped).__name__}.fillna is deprecated"
41-
with tm.assert_produces_warning(warn, match=msg, raise_on_extra_warnings=False):
39+
warn = FutureWarning if groupby_func == "corrwith" else None
40+
msg = f"{type(grouped).__name__}.corrwith is deprecated"
41+
with tm.assert_produces_warning(warn, match=msg):
4242
result1 = getattr(grouped, groupby_func)(*args)
43-
with tm.assert_produces_warning(warn, match=msg, raise_on_extra_warnings=False):
43+
with tm.assert_produces_warning(warn, match=msg):
4444
result2 = grouped.agg(groupby_func, *args)
4545

4646
# Reduction or transformation kernels should preserve type

pandas/tests/groupby/test_numeric_only.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,11 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys):
278278
kernel in ("first", "last")
279279
or (
280280
# kernels that work on any dtype and don't have numeric_only arg
281-
kernel in ("any", "all", "bfill", "ffill", "fillna", "nth", "nunique")
281+
kernel in ("any", "all", "bfill", "ffill", "nth", "nunique")
282282
and numeric_only is lib.no_default
283283
)
284284
):
285-
warn = FutureWarning if kernel == "fillna" else None
286-
msg = "DataFrameGroupBy.fillna is deprecated"
287-
with tm.assert_produces_warning(warn, match=msg):
288-
result = method(*args, **kwargs)
285+
result = method(*args, **kwargs)
289286
assert "b" in result.columns
290287
elif has_arg:
291288
assert numeric_only is not True

pandas/tests/groupby/test_raises.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def test_groupby_raises_string(
144144
),
145145
"diff": (TypeError, "unsupported operand type"),
146146
"ffill": (None, ""),
147-
"fillna": (None, ""),
148147
"first": (None, ""),
149148
"idxmax": (None, ""),
150149
"idxmin": (None, ""),
@@ -211,10 +210,7 @@ def test_groupby_raises_string(
211210
elif groupby_func == "corrwith":
212211
msg = "Cannot perform reduction 'mean' with string dtype"
213212

214-
if groupby_func == "fillna":
215-
kind = "Series" if groupby_series else "DataFrame"
216-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
217-
elif groupby_func == "corrwith":
213+
if groupby_func == "corrwith":
218214
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
219215
else:
220216
warn_msg = ""
@@ -301,7 +297,6 @@ def test_groupby_raises_datetime(
301297
"cumsum": (TypeError, "datetime64 type does not support operation 'cumsum'"),
302298
"diff": (None, ""),
303299
"ffill": (None, ""),
304-
"fillna": (None, ""),
305300
"first": (None, ""),
306301
"idxmax": (None, ""),
307302
"idxmin": (None, ""),
@@ -333,10 +328,7 @@ def test_groupby_raises_datetime(
333328
"var": (TypeError, "datetime64 type does not support operation 'var'"),
334329
}[groupby_func]
335330

336-
if groupby_func == "fillna":
337-
kind = "Series" if groupby_series else "DataFrame"
338-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
339-
elif groupby_func == "corrwith":
331+
if groupby_func == "corrwith":
340332
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
341333
else:
342334
warn_msg = ""
@@ -457,7 +449,6 @@ def test_groupby_raises_category(
457449
r"unsupported operand type\(s\) for -: 'Categorical' and 'Categorical'",
458450
),
459451
"ffill": (None, ""),
460-
"fillna": (None, ""), # no-op with CoW
461452
"first": (None, ""),
462453
"idxmax": (None, ""),
463454
"idxmin": (None, ""),
@@ -532,10 +523,7 @@ def test_groupby_raises_category(
532523
),
533524
}[groupby_func]
534525

535-
if groupby_func == "fillna":
536-
kind = "Series" if groupby_series else "DataFrame"
537-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
538-
elif groupby_func == "corrwith":
526+
if groupby_func == "corrwith":
539527
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
540528
else:
541529
warn_msg = ""
@@ -650,7 +638,6 @@ def test_groupby_raises_category_on_category(
650638
),
651639
"diff": (TypeError, "unsupported operand type"),
652640
"ffill": (None, ""),
653-
"fillna": (None, ""), # no-op with CoW
654641
"first": (None, ""),
655642
"idxmax": (ValueError, "empty group due to unobserved categories")
656643
if empty_groups
@@ -710,10 +697,7 @@ def test_groupby_raises_category_on_category(
710697
),
711698
}[groupby_func]
712699

713-
if groupby_func == "fillna":
714-
kind = "Series" if groupby_series else "DataFrame"
715-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
716-
elif groupby_func == "corrwith":
700+
if groupby_func == "corrwith":
717701
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
718702
else:
719703
warn_msg = ""

pandas/tests/groupby/transform/test_transform.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ def test_transform_transformation_func(transformation_func):
329329
if transformation_func == "cumcount":
330330
test_op = lambda x: x.transform("cumcount")
331331
mock_op = lambda x: Series(range(len(x)), x.index)
332-
elif transformation_func == "fillna":
333-
test_op = lambda x: x.transform("fillna", value=0)
334-
mock_op = lambda x: x.fillna(value=0)
335332
elif transformation_func == "ngroup":
336333
test_op = lambda x: x.transform("ngroup")
337334
counter = -1
@@ -1436,11 +1433,7 @@ def test_null_group_str_transformer_series(dropna, transformation_func):
14361433
dtype = object if transformation_func in ("any", "all") else None
14371434
buffer.append(Series([np.nan], index=[3], dtype=dtype))
14381435
expected = concat(buffer)
1439-
1440-
warn = FutureWarning if transformation_func == "fillna" else None
1441-
msg = "SeriesGroupBy.fillna is deprecated"
1442-
with tm.assert_produces_warning(warn, match=msg):
1443-
result = gb.transform(transformation_func, *args)
1436+
result = gb.transform(transformation_func, *args)
14441437

14451438
tm.assert_equal(result, expected)
14461439

0 commit comments

Comments
 (0)