diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 7d028935ad175..c504afa195192 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -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`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 6008e6b6cb566..d8809b64bd98d 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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( @@ -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( diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 0645afd861029..b3f63db05dd28 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -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)() diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 9fded26c37caf..b30f2ca4b4acd 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -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)()