Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Deprecate pad and backfill methods #13140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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,
Expand Down
38 changes: 36 additions & 2 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
"""
Expand Down
16 changes: 10 additions & 6 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)


Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down