Skip to content

Commit 7f28f2f

Browse files
authored
Deprecate groupby fillna (#15000)
Deprecated in pandas 2.2 pandas-dev/pandas#55719 Authors: - Matthew Roeschke (https://github.com/mroeschke) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: #15000
1 parent 73bac83 commit 7f28f2f

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

python/cudf/cudf/core/groupby/groupby.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,12 @@ def fillna(
22272227
-------
22282228
DataFrame or Series
22292229
"""
2230+
warnings.warn(
2231+
"groupby fillna is deprecated and "
2232+
"will be removed in a future version. Use groupby ffill or groupby bfill "
2233+
"for forward or backward filling instead.",
2234+
FutureWarning,
2235+
)
22302236
if inplace:
22312237
raise NotImplementedError("Does not support inplace yet.")
22322238
if limit is not None:
@@ -2244,17 +2250,6 @@ def fillna(
22442250
if method is not None:
22452251
if method not in {"ffill", "bfill"}:
22462252
raise ValueError("Method can only be of 'ffill', 'bfill'.")
2247-
# Do not remove until pandas 3.0 support is added.
2248-
assert (
2249-
PANDAS_LT_300
2250-
), "Need to drop after pandas-3.0 support is added."
2251-
warnings.warn(
2252-
f"{type(self).__name__}.fillna with 'method' is "
2253-
"deprecated and will raise in a future version. "
2254-
"Use obj.ffill() or obj.bfill() instead.",
2255-
FutureWarning,
2256-
)
2257-
22582253
return getattr(self, method, limit)()
22592254

22602255
values = self.obj.__class__._from_data(

python/cudf/cudf/tests/test_groupby.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import cudf
2121
from cudf import DataFrame, Series
2222
from cudf.api.extensions import no_default
23-
from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_210
23+
from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_210, PANDAS_GE_220
2424
from cudf.core.udf._ops import arith_ops, comparison_ops, unary_ops
2525
from cudf.core.udf.groupby_typing import SUPPORTED_GROUPBY_NUMPY_TYPES
2626
from cudf.core.udf.utils import UDFError, precompiled
@@ -2745,10 +2745,10 @@ def test_groupby_fillna_multi_value(nelem):
27452745
}
27462746
# cudf can't fillna with a pandas.Timedelta type
27472747
fill_values["4"] = fill_values["4"].to_numpy()
2748-
2749-
expect = pdf.groupby(key_col).fillna(value=fill_values)
2750-
2751-
got = gdf.groupby(key_col).fillna(value=fill_values)
2748+
with expect_warning_if(PANDAS_GE_220):
2749+
expect = pdf.groupby(key_col).fillna(value=fill_values)
2750+
with pytest.warns(FutureWarning):
2751+
got = gdf.groupby(key_col).fillna(value=fill_values)
27522752

27532753
assert_groupby_results_equal(expect[value_cols], got[value_cols])
27542754

@@ -2791,11 +2791,12 @@ def test_groupby_fillna_multi_value_df(nelem):
27912791
# cudf can't fillna with a pandas.Timedelta type
27922792
fill_values["4"] = fill_values["4"].to_numpy()
27932793
fill_values = pd.DataFrame(fill_values, index=pdf.index)
2794-
2795-
expect = pdf.groupby(key_col).fillna(value=fill_values)
2794+
with expect_warning_if(PANDAS_GE_220):
2795+
expect = pdf.groupby(key_col).fillna(value=fill_values)
27962796

27972797
fill_values = cudf.from_pandas(fill_values)
2798-
got = gdf.groupby(key_col).fillna(value=fill_values)
2798+
with pytest.warns(FutureWarning):
2799+
got = gdf.groupby(key_col).fillna(value=fill_values)
27992800

28002801
assert_groupby_results_equal(expect[value_cols], got[value_cols])
28012802

@@ -2812,11 +2813,13 @@ def test_groupby_various_by_fillna(by, data, args):
28122813
ps = pd.Series(data)
28132814
gs = cudf.from_pandas(ps)
28142815

2815-
with expect_warning_if(PANDAS_GE_210 and "method" in args):
2816+
with expect_warning_if(
2817+
(PANDAS_GE_210 and "method" in args) or PANDAS_GE_220
2818+
):
28162819
expect = ps.groupby(by).fillna(**args)
28172820
if isinstance(by, pd.Grouper):
28182821
by = cudf.Grouper(level=by.level)
2819-
with expect_warning_if("method" in args):
2822+
with pytest.warns(FutureWarning):
28202823
got = gs.groupby(by).fillna(**args)
28212824

28222825
assert_groupby_results_equal(expect, got, check_dtype=False)

0 commit comments

Comments
 (0)