Skip to content

Commit a17bd64

Browse files
authored
DEP: Enforce deprecation of pad/backfill for groupby and resample (#49081)
* DEP: Enforce deprecation of pad/backfill for groupby and resample * Remove test * Add whatsnew
1 parent 145e527 commit a17bd64

File tree

9 files changed

+1
-130
lines changed

9 files changed

+1
-130
lines changed

doc/source/reference/groupby.rst

-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ Function application
6565

6666
DataFrameGroupBy.all
6767
DataFrameGroupBy.any
68-
DataFrameGroupBy.backfill
6968
DataFrameGroupBy.bfill
7069
DataFrameGroupBy.corr
7170
DataFrameGroupBy.corrwith
@@ -94,7 +93,6 @@ Function application
9493
DataFrameGroupBy.nth
9594
DataFrameGroupBy.nunique
9695
DataFrameGroupBy.ohlc
97-
DataFrameGroupBy.pad
9896
DataFrameGroupBy.pct_change
9997
DataFrameGroupBy.prod
10098
DataFrameGroupBy.quantile
@@ -120,7 +118,6 @@ Function application
120118

121119
SeriesGroupBy.all
122120
SeriesGroupBy.any
123-
SeriesGroupBy.backfill
124121
SeriesGroupBy.bfill
125122
SeriesGroupBy.corr
126123
SeriesGroupBy.count
@@ -153,7 +150,6 @@ Function application
153150
SeriesGroupBy.nunique
154151
SeriesGroupBy.unique
155152
SeriesGroupBy.ohlc
156-
SeriesGroupBy.pad
157153
SeriesGroupBy.pct_change
158154
SeriesGroupBy.prod
159155
SeriesGroupBy.quantile

doc/source/reference/resampling.rst

-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ Upsampling
3535
:toctree: api/
3636

3737
Resampler.ffill
38-
Resampler.backfill
3938
Resampler.bfill
40-
Resampler.pad
4139
Resampler.nearest
4240
Resampler.fillna
4341
Resampler.asfreq

doc/source/whatsnew/v2.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Deprecations
145145
Removal of prior version deprecations/changes
146146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147147
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
148-
-
148+
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
149149

150150
.. ---------------------------------------------------------------------------
151151
.. _whatsnew_200.performance:

pandas/core/groupby/base.py

-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:
7373

7474
transformation_kernels = frozenset(
7575
[
76-
"backfill",
7776
"bfill",
7877
"cumcount",
7978
"cummax",
@@ -84,7 +83,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:
8483
"ffill",
8584
"fillna",
8685
"ngroup",
87-
"pad",
8886
"pct_change",
8987
"rank",
9088
"shift",

pandas/core/groupby/groupby.py

-50
Original file line numberDiff line numberDiff line change
@@ -2936,31 +2936,6 @@ def ffill(self, limit=None):
29362936
"""
29372937
return self._fill("ffill", limit=limit)
29382938

2939-
def pad(self, limit=None):
2940-
"""
2941-
Forward fill the values.
2942-
2943-
.. deprecated:: 1.4
2944-
Use ffill instead.
2945-
2946-
Parameters
2947-
----------
2948-
limit : int, optional
2949-
Limit of how many values to fill.
2950-
2951-
Returns
2952-
-------
2953-
Series or DataFrame
2954-
Object with missing values filled.
2955-
"""
2956-
warnings.warn(
2957-
"pad is deprecated and will be removed in a future version. "
2958-
"Use ffill instead.",
2959-
FutureWarning,
2960-
stacklevel=find_stack_level(),
2961-
)
2962-
return self.ffill(limit=limit)
2963-
29642939
@final
29652940
@Substitution(name="groupby")
29662941
def bfill(self, limit=None):
@@ -2986,31 +2961,6 @@ def bfill(self, limit=None):
29862961
"""
29872962
return self._fill("bfill", limit=limit)
29882963

2989-
def backfill(self, limit=None):
2990-
"""
2991-
Backward fill the values.
2992-
2993-
.. deprecated:: 1.4
2994-
Use bfill instead.
2995-
2996-
Parameters
2997-
----------
2998-
limit : int, optional
2999-
Limit of how many values to fill.
3000-
3001-
Returns
3002-
-------
3003-
Series or DataFrame
3004-
Object with missing values filled.
3005-
"""
3006-
warnings.warn(
3007-
"backfill is deprecated and will be removed in a future version. "
3008-
"Use bfill instead.",
3009-
FutureWarning,
3010-
stacklevel=find_stack_level(),
3011-
)
3012-
return self.bfill(limit=limit)
3013-
30142964
@final
30152965
@Substitution(name="groupby")
30162966
@Substitution(see_also=_common_see_also)

pandas/core/resample.py

-51
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
final,
1212
no_type_check,
1313
)
14-
import warnings
1514

1615
import numpy as np
1716

@@ -50,7 +49,6 @@
5049
deprecate_nonkeyword_arguments,
5150
doc,
5251
)
53-
from pandas.util._exceptions import find_stack_level
5452

5553
from pandas.core.dtypes.generic import (
5654
ABCDataFrame,
@@ -562,30 +560,6 @@ def ffill(self, limit=None):
562560
"""
563561
return self._upsample("ffill", limit=limit)
564562

565-
def pad(self, limit=None):
566-
"""
567-
Forward fill the values.
568-
569-
.. deprecated:: 1.4
570-
Use ffill instead.
571-
572-
Parameters
573-
----------
574-
limit : int, optional
575-
Limit of how many values to fill.
576-
577-
Returns
578-
-------
579-
An upsampled Series.
580-
"""
581-
warnings.warn(
582-
"pad is deprecated and will be removed in a future version. "
583-
"Use ffill instead.",
584-
FutureWarning,
585-
stacklevel=find_stack_level(),
586-
)
587-
return self.ffill(limit=limit)
588-
589563
def nearest(self, limit=None):
590564
"""
591565
Resample by using the nearest value.
@@ -748,31 +722,6 @@ def bfill(self, limit=None):
748722
"""
749723
return self._upsample("bfill", limit=limit)
750724

751-
def backfill(self, limit=None):
752-
"""
753-
Backward fill the values.
754-
755-
.. deprecated:: 1.4
756-
Use bfill instead.
757-
758-
Parameters
759-
----------
760-
limit : int, optional
761-
Limit of how many values to fill.
762-
763-
Returns
764-
-------
765-
Series, DataFrame
766-
An upsampled Series or DataFrame with backward filled NaN values.
767-
"""
768-
warnings.warn(
769-
"backfill is deprecated and will be removed in a future version. "
770-
"Use bfill instead.",
771-
FutureWarning,
772-
stacklevel=find_stack_level(),
773-
)
774-
return self.bfill(limit=limit)
775-
776725
def fillna(self, method, limit=None):
777726
"""
778727
Fill missing values introduced by upsampling.

pandas/tests/groupby/test_allowlist.py

-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ def test_tab_completion(mframe):
217217
"idxmin",
218218
"ffill",
219219
"bfill",
220-
"pad",
221-
"backfill",
222220
"rolling",
223221
"expanding",
224222
"pipe",

pandas/tests/groupby/test_groupby.py

-9
Original file line numberDiff line numberDiff line change
@@ -2778,15 +2778,6 @@ def test_rolling_wrong_param_min_period():
27782778
test_df.groupby("name")["val"].rolling(window=2, min_period=1).sum()
27792779

27802780

2781-
def test_pad_backfill_deprecation():
2782-
# GH 33396
2783-
s = Series([1, 2, 3])
2784-
with tm.assert_produces_warning(FutureWarning, match="backfill"):
2785-
s.groupby(level=0).backfill()
2786-
with tm.assert_produces_warning(FutureWarning, match="pad"):
2787-
s.groupby(level=0).pad()
2788-
2789-
27902781
def test_by_column_values_with_same_starting_value():
27912782
# GH29635
27922783
df = DataFrame(

pandas/tests/resample/test_deprecated.py

-9
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,3 @@ def test_interpolate_posargs_deprecation():
305305

306306
expected.index._data.freq = "3s"
307307
tm.assert_series_equal(result, expected)
308-
309-
310-
def test_pad_backfill_deprecation():
311-
# GH 33396
312-
s = Series([1, 2, 3], index=date_range("20180101", periods=3, freq="h"))
313-
with tm.assert_produces_warning(FutureWarning, match="backfill"):
314-
s.resample("30min").backfill()
315-
with tm.assert_produces_warning(FutureWarning, match="pad"):
316-
s.resample("30min").pad()

0 commit comments

Comments
 (0)