From 7f28f2f55253bcc6cf109242f6a2a126688cb16e Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 8 Feb 2024 03:19:19 -1000 Subject: [PATCH] Deprecate groupby fillna (#15000) Deprecated in pandas 2.2 https://github.com/pandas-dev/pandas/pull/55719 Authors: - Matthew Roeschke (https://github.com/mroeschke) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: https://github.com/rapidsai/cudf/pull/15000 --- python/cudf/cudf/core/groupby/groupby.py | 17 ++++++----------- python/cudf/cudf/tests/test_groupby.py | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/python/cudf/cudf/core/groupby/groupby.py b/python/cudf/cudf/core/groupby/groupby.py index 78593f20421..9e8d9908df2 100644 --- a/python/cudf/cudf/core/groupby/groupby.py +++ b/python/cudf/cudf/core/groupby/groupby.py @@ -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: @@ -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( diff --git a/python/cudf/cudf/tests/test_groupby.py b/python/cudf/cudf/tests/test_groupby.py index a0b86d735cc..bd48e5bfd31 100644 --- a/python/cudf/cudf/tests/test_groupby.py +++ b/python/cudf/cudf/tests/test_groupby.py @@ -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 @@ -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]) @@ -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]) @@ -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)