Skip to content

Commit

Permalink
Deprecate groupby fillna (#15000)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mroeschke authored Feb 8, 2024
1 parent 73bac83 commit 7f28f2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
17 changes: 6 additions & 11 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2227,6 +2227,12 @@ def fillna(
-------
DataFrame or Series
"""
warnings.warn(
"groupby fillna is deprecated and "
"will be removed in a future version. Use groupby ffill or groupby bfill "
"for forward or backward filling instead.",
FutureWarning,
)
if inplace:
raise NotImplementedError("Does not support inplace yet.")
if limit is not None:
Expand All @@ -2244,17 +2250,6 @@ def fillna(
if method is not None:
if method not in {"ffill", "bfill"}:
raise ValueError("Method can only be of 'ffill', 'bfill'.")
# Do not remove until pandas 3.0 support is added.
assert (
PANDAS_LT_300
), "Need to drop after pandas-3.0 support is added."
warnings.warn(
f"{type(self).__name__}.fillna with 'method' is "
"deprecated and will raise in a future version. "
"Use obj.ffill() or obj.bfill() instead.",
FutureWarning,
)

return getattr(self, method, limit)()

values = self.obj.__class__._from_data(
Expand Down
23 changes: 13 additions & 10 deletions python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import cudf
from cudf import DataFrame, Series
from cudf.api.extensions import no_default
from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_210
from cudf.core._compat import PANDAS_GE_200, PANDAS_GE_210, PANDAS_GE_220
from cudf.core.udf._ops import arith_ops, comparison_ops, unary_ops
from cudf.core.udf.groupby_typing import SUPPORTED_GROUPBY_NUMPY_TYPES
from cudf.core.udf.utils import UDFError, precompiled
Expand Down Expand Up @@ -2745,10 +2745,10 @@ def test_groupby_fillna_multi_value(nelem):
}
# cudf can't fillna with a pandas.Timedelta type
fill_values["4"] = fill_values["4"].to_numpy()

expect = pdf.groupby(key_col).fillna(value=fill_values)

got = gdf.groupby(key_col).fillna(value=fill_values)
with expect_warning_if(PANDAS_GE_220):
expect = pdf.groupby(key_col).fillna(value=fill_values)
with pytest.warns(FutureWarning):
got = gdf.groupby(key_col).fillna(value=fill_values)

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

Expand Down Expand Up @@ -2791,11 +2791,12 @@ def test_groupby_fillna_multi_value_df(nelem):
# cudf can't fillna with a pandas.Timedelta type
fill_values["4"] = fill_values["4"].to_numpy()
fill_values = pd.DataFrame(fill_values, index=pdf.index)

expect = pdf.groupby(key_col).fillna(value=fill_values)
with expect_warning_if(PANDAS_GE_220):
expect = pdf.groupby(key_col).fillna(value=fill_values)

fill_values = cudf.from_pandas(fill_values)
got = gdf.groupby(key_col).fillna(value=fill_values)
with pytest.warns(FutureWarning):
got = gdf.groupby(key_col).fillna(value=fill_values)

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

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

with expect_warning_if(PANDAS_GE_210 and "method" in args):
with expect_warning_if(
(PANDAS_GE_210 and "method" in args) or PANDAS_GE_220
):
expect = ps.groupby(by).fillna(**args)
if isinstance(by, pd.Grouper):
by = cudf.Grouper(level=by.level)
with expect_warning_if("method" in args):
with pytest.warns(FutureWarning):
got = gs.groupby(by).fillna(**args)

assert_groupby_results_equal(expect, got, check_dtype=False)
Expand Down

0 comments on commit 7f28f2f

Please sign in to comment.