Skip to content

Commit 326de11

Browse files
authored
DEP: Deprecated pad/backfill for Series/DataFrame (#51221)
1 parent 1bb128e commit 326de11

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

doc/source/whatsnew/v2.0.0.rst

+4
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,10 @@ Deprecations
786786
- 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`)
787787
- Deprecated :meth:`Grouper.groups`, use :meth:`Groupby.groups` instead (:issue:`51182`)
788788
- Deprecated :meth:`Grouper.grouper`, use :meth:`Groupby.grouper` instead (:issue:`51182`)
789+
- Deprecated :meth:`Series.pad` in favor of :meth:`Series.ffill` (:issue:`33396`)
790+
- Deprecated :meth:`Series.backfill` in favor of :meth:`Series.bfill` (:issue:`33396`)
791+
- Deprecated :meth:`DataFrame.pad` in favor of :meth:`DataFrame.ffill` (:issue:`33396`)
792+
- Deprecated :meth:`DataFrame.backfill` in favor of :meth:`DataFrame.bfill` (:issue:`33396`)
789793
-
790794

791795
.. ---------------------------------------------------------------------------

pandas/core/generic.py

+56-2
Original file line numberDiff line numberDiff line change
@@ -7001,7 +7001,34 @@ def ffill(
70017001
method="ffill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
70027002
)
70037003

7004-
pad = ffill
7004+
@doc(klass=_shared_doc_kwargs["klass"])
7005+
def pad(
7006+
self: NDFrameT,
7007+
*,
7008+
axis: None | Axis = None,
7009+
inplace: bool_t = False,
7010+
limit: None | int = None,
7011+
downcast: dict | None = None,
7012+
) -> NDFrameT | None:
7013+
"""
7014+
Synonym for :meth:`DataFrame.fillna` with ``method='ffill'``.
7015+
7016+
.. deprecated:: 2.0
7017+
7018+
{klass}.pad is deprecated. Use {klass}.ffill instead.
7019+
7020+
Returns
7021+
-------
7022+
{klass} or None
7023+
Object with missing values filled or None if ``inplace=True``.
7024+
"""
7025+
warnings.warn(
7026+
"DataFrame.pad/Series.pad is deprecated. Use "
7027+
"DataFrame.ffill/Series.ffill instead",
7028+
FutureWarning,
7029+
stacklevel=find_stack_level(),
7030+
)
7031+
return self.ffill(axis=axis, inplace=inplace, limit=limit, downcast=downcast)
70057032

70067033
@overload
70077034
def bfill(
@@ -7057,7 +7084,34 @@ def bfill(
70577084
method="bfill", axis=axis, inplace=inplace, limit=limit, downcast=downcast
70587085
)
70597086

7060-
backfill = bfill
7087+
@doc(klass=_shared_doc_kwargs["klass"])
7088+
def backfill(
7089+
self: NDFrameT,
7090+
*,
7091+
axis: None | Axis = None,
7092+
inplace: bool_t = False,
7093+
limit: None | int = None,
7094+
downcast: dict | None = None,
7095+
) -> NDFrameT | None:
7096+
"""
7097+
Synonym for :meth:`DataFrame.fillna` with ``method='bfill'``.
7098+
7099+
.. deprecated:: 2.0
7100+
7101+
{klass}.backfill is deprecated. Use {klass}.backfill instead.
7102+
7103+
Returns
7104+
-------
7105+
{klass} or None
7106+
Object with missing values filled or None if ``inplace=True``.
7107+
"""
7108+
warnings.warn(
7109+
"DataFrame.backfill/Series.backfill is deprecated. Use "
7110+
"DataFrame.bfill/Series.bfill instead",
7111+
FutureWarning,
7112+
stacklevel=find_stack_level(),
7113+
)
7114+
return self.bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast)
70617115

70627116
@overload
70637117
def replace(

pandas/tests/frame/methods/test_fillna.py

+8
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,11 @@ def test_fillna_nones_inplace():
769769

770770
expected = DataFrame([[1, 2], [1, 2]], columns=["A", "B"])
771771
tm.assert_frame_equal(df, expected)
772+
773+
774+
@pytest.mark.parametrize("func", ["pad", "backfill"])
775+
def test_pad_backfill_deprecated(func):
776+
# GH#33396
777+
df = DataFrame({"a": [1, 2, 3]})
778+
with tm.assert_produces_warning(FutureWarning):
779+
getattr(df, func)()

pandas/tests/series/methods/test_fillna.py

+7
Original file line numberDiff line numberDiff line change
@@ -970,3 +970,10 @@ def test_fillna_parr(self):
970970
filled = ser.fillna(method="pad")
971971

972972
tm.assert_series_equal(filled, expected)
973+
974+
@pytest.mark.parametrize("func", ["pad", "backfill"])
975+
def test_pad_backfill_deprecated(self, func):
976+
# GH#33396
977+
ser = Series([1, 2, 3])
978+
with tm.assert_produces_warning(FutureWarning):
979+
getattr(ser, func)()

0 commit comments

Comments
 (0)