diff --git a/python/cudf/cudf/core/groupby/groupby.py b/python/cudf/cudf/core/groupby/groupby.py index cb4c0f6b48b..5e98db0d575 100644 --- a/python/cudf/cudf/core/groupby/groupby.py +++ b/python/cudf/cudf/core/groupby/groupby.py @@ -1948,6 +1948,9 @@ def _scan_fill(self, method: str, limit: int) -> DataFrameOrSeries: def pad(self, limit=None): """Forward fill NA values. + .. deprecated:: 23.06 + `pad` is deprecated, use `ffill` instead. + Parameters ---------- limit : int, default None @@ -1957,13 +1960,33 @@ def pad(self, limit=None): if limit is not None: raise NotImplementedError("Does not support limit param yet.") + warnings.warn( + "pad is deprecated and will be removed in a future version. " + "Use ffill instead.", + FutureWarning, + ) return self._scan_fill("ffill", limit) - ffill = pad + def ffill(self, limit=None): + """Forward fill NA values. + + Parameters + ---------- + limit : int, default None + Unsupported + """ + + if limit is not None: + raise NotImplementedError("Does not support limit param yet.") + + return self._scan_fill("ffill", limit) def backfill(self, limit=None): """Backward fill NA values. + .. deprecated:: 23.06 + `backfill` is deprecated, use `bfill` instead. + Parameters ---------- limit : int, default None @@ -1972,9 +1995,25 @@ def backfill(self, limit=None): if limit is not None: raise NotImplementedError("Does not support limit param yet.") + warnings.warn( + "backfill is deprecated and will be removed in a future version. " + "Use bfill instead.", + FutureWarning, + ) return self._scan_fill("bfill", limit) - bfill = backfill + def bfill(self, limit=None): + """Backward fill NA values. + + Parameters + ---------- + limit : int, default None + Unsupported + """ + if limit is not None: + raise NotImplementedError("Does not support limit param yet.") + + return self._scan_fill("bfill", limit) def fillna( self, diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index 9ce7c1ac1d9..97dfb16bd32 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -1994,7 +1994,24 @@ def bfill(self, value=None, axis=None, inplace=None, limit=None): limit=limit, ) - backfill = bfill + @_cudf_nvtx_annotate + def backfill(self, value=None, axis=None, inplace=None, limit=None): + """ + Synonym for :meth:`Series.fillna` with ``method='bfill'``. + + .. deprecated:: 23.06 + Use `DataFrame.bfill/Series.bfill` instead. + + Returns + ------- + Object with missing values filled or None if ``inplace=True``. + """ + warnings.warn( + "DataFrame.backfill/Series.backfill is deprecated. Use " + "DataFrame.bfill/Series.bfill instead", + FutureWarning, + ) + return self.bfill(value=value, axis=axis, inplace=inplace, limit=limit) @_cudf_nvtx_annotate def ffill(self, value=None, axis=None, inplace=None, limit=None): @@ -2013,7 +2030,24 @@ def ffill(self, value=None, axis=None, inplace=None, limit=None): limit=limit, ) - pad = ffill + @_cudf_nvtx_annotate + def pad(self, value=None, axis=None, inplace=None, limit=None): + """ + Synonym for :meth:`Series.fillna` with ``method='ffill'``. + + .. deprecated:: 23.06 + Use `DataFrame.ffill/Series.ffill` instead. + + Returns + ------- + Object with missing values filled or None if ``inplace=True``. + """ + warnings.warn( + "DataFrame.pad/Series.pad is deprecated. Use " + "DataFrame.ffill/Series.ffill instead", + FutureWarning, + ) + return self.ffill(value=value, axis=axis, inplace=inplace, limit=limit) def add_prefix(self, prefix): """ diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index 70b7f74017c..e38d42f1c94 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -7574,11 +7574,13 @@ def test_dataframe_append_dataframe_lists(df, other, sort, ignore_index): pd.Series([1, 2, 3, None, np.nan, 5, 6, np.nan]), ], ) -def test_dataframe_bfill(df): +@pytest.mark.parametrize("alias", ["bfill", "backfill"]) +def test_dataframe_bfill(df, alias): gdf = cudf.from_pandas(df) - actual = df.bfill() - expected = gdf.bfill() + actual = getattr(df, alias)() + with expect_warning_if(alias == "backfill"): + expected = getattr(gdf, alias)() assert_eq(expected, actual) @@ -7589,11 +7591,13 @@ def test_dataframe_bfill(df): pd.Series([1, 2, 3, None, np.nan, 5, 6, np.nan]), ], ) -def test_dataframe_ffill(df): +@pytest.mark.parametrize("alias", ["ffill", "pad"]) +def test_dataframe_ffill(df, alias): gdf = cudf.from_pandas(df) - actual = df.ffill() - expected = gdf.ffill() + actual = getattr(df, alias)() + with expect_warning_if(alias == "pad"): + expected = getattr(gdf, alias)() assert_eq(expected, actual) diff --git a/python/cudf/cudf/tests/test_groupby.py b/python/cudf/cudf/tests/test_groupby.py index e58d70f49c7..24db7008804 100644 --- a/python/cudf/cudf/tests/test_groupby.py +++ b/python/cudf/cudf/tests/test_groupby.py @@ -2538,7 +2538,8 @@ def test_groupby_fillna_method(nelem, method): gdf = cudf.from_pandas(pdf) expect = pdf.groupby(key_col).fillna(method=method) - got = gdf.groupby(key_col).fillna(method=method) + with expect_warning_if(method in {"pad", "backfill"}): + got = gdf.groupby(key_col).fillna(method=method) assert_groupby_results_equal( expect[value_cols], got[value_cols], sort=False