Skip to content

DEP: Deprecated pad/backfill for Series/DataFrame #51221

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

Merged
merged 1 commit into from
Feb 8, 2023
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
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,10 @@ Deprecations
- Deprecated calling ``float`` or ``int`` on a single element :class:`Series` to return a ``float`` or ``int`` respectively. Extract the element before calling ``float`` or ``int`` instead (:issue:`51101`)
- Deprecated :meth:`Grouper.groups`, use :meth:`Groupby.groups` instead (:issue:`51182`)
- Deprecated :meth:`Grouper.grouper`, use :meth:`Groupby.grouper` instead (:issue:`51182`)
- Deprecated :meth:`Series.pad` in favor of :meth:`Series.ffill` (:issue:`33396`)
- Deprecated :meth:`Series.backfill` in favor of :meth:`Series.bfill` (:issue:`33396`)
- Deprecated :meth:`DataFrame.pad` in favor of :meth:`DataFrame.ffill` (:issue:`33396`)
- Deprecated :meth:`DataFrame.backfill` in favor of :meth:`DataFrame.bfill` (:issue:`33396`)
-

.. ---------------------------------------------------------------------------
Expand Down
58 changes: 56 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6999,7 +6999,34 @@ def ffill(
method="ffill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
)

pad = ffill
@doc(klass=_shared_doc_kwargs["klass"])
def pad(
self: NDFrameT,
*,
axis: None | Axis = None,
inplace: bool_t = False,
limit: None | int = None,
downcast: dict | None = None,
) -> NDFrameT | None:
"""
Synonym for :meth:`DataFrame.fillna` with ``method='ffill'``.

.. deprecated:: 2.0

{klass}.pad is deprecated. Use {klass}.ffill instead.

Returns
-------
{klass} or None
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,
stacklevel=find_stack_level(),
)
return self.ffill(axis=axis, inplace=inplace, limit=limit, downcast=downcast)

@overload
def bfill(
Expand Down Expand Up @@ -7055,7 +7082,34 @@ def bfill(
method="bfill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
)

backfill = bfill
@doc(klass=_shared_doc_kwargs["klass"])
def backfill(
self: NDFrameT,
*,
axis: None | Axis = None,
inplace: bool_t = False,
limit: None | int = None,
downcast: dict | None = None,
) -> NDFrameT | None:
"""
Synonym for :meth:`DataFrame.fillna` with ``method='bfill'``.

.. deprecated:: 2.0

{klass}.backfill is deprecated. Use {klass}.backfill instead.

Returns
-------
{klass} or None
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,
stacklevel=find_stack_level(),
)
return self.bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast)

@overload
def replace(
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,11 @@ def test_fillna_nones_inplace():

expected = DataFrame([[1, 2], [1, 2]], columns=["A", "B"])
tm.assert_frame_equal(df, expected)


@pytest.mark.parametrize("func", ["pad", "backfill"])
def test_pad_backfill_deprecated(func):
# GH#33396
df = DataFrame({"a": [1, 2, 3]})
with tm.assert_produces_warning(FutureWarning):
getattr(df, func)()
7 changes: 7 additions & 0 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,10 @@ def test_fillna_parr(self):
filled = ser.fillna(method="pad")

tm.assert_series_equal(filled, expected)

@pytest.mark.parametrize("func", ["pad", "backfill"])
def test_pad_backfill_deprecated(self, func):
# GH#33396
ser = Series([1, 2, 3])
with tm.assert_produces_warning(FutureWarning):
getattr(ser, func)()