Skip to content

DEP: Enforce deprecation of pad/backfill for groupby and resample #49081

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 4 commits into from
Oct 19, 2022
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: 0 additions & 4 deletions doc/source/reference/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Function application

DataFrameGroupBy.all
DataFrameGroupBy.any
DataFrameGroupBy.backfill
DataFrameGroupBy.bfill
DataFrameGroupBy.corr
DataFrameGroupBy.corrwith
Expand Down Expand Up @@ -94,7 +93,6 @@ Function application
DataFrameGroupBy.nth
DataFrameGroupBy.nunique
DataFrameGroupBy.ohlc
DataFrameGroupBy.pad
DataFrameGroupBy.pct_change
DataFrameGroupBy.prod
DataFrameGroupBy.quantile
Expand All @@ -120,7 +118,6 @@ Function application

SeriesGroupBy.all
SeriesGroupBy.any
SeriesGroupBy.backfill
SeriesGroupBy.bfill
SeriesGroupBy.corr
SeriesGroupBy.count
Expand Down Expand Up @@ -153,7 +150,6 @@ Function application
SeriesGroupBy.nunique
SeriesGroupBy.unique
SeriesGroupBy.ohlc
SeriesGroupBy.pad
SeriesGroupBy.pct_change
SeriesGroupBy.prod
SeriesGroupBy.quantile
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/resampling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ Upsampling
:toctree: api/

Resampler.ffill
Resampler.backfill
Resampler.bfill
Resampler.pad
Resampler.nearest
Resampler.fillna
Resampler.asfreq
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Deprecations
Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
-
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)

.. ---------------------------------------------------------------------------
.. _whatsnew_200.performance:
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/groupby/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:

transformation_kernels = frozenset(
[
"backfill",
"bfill",
"cumcount",
"cummax",
Expand All @@ -84,7 +83,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]:
"ffill",
"fillna",
"ngroup",
"pad",
"pct_change",
"rank",
"shift",
Expand Down
50 changes: 0 additions & 50 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2936,31 +2936,6 @@ def ffill(self, limit=None):
"""
return self._fill("ffill", limit=limit)

def pad(self, limit=None):
"""
Forward fill the values.

.. deprecated:: 1.4
Use ffill instead.

Parameters
----------
limit : int, optional
Limit of how many values to fill.

Returns
-------
Series or DataFrame
Object with missing values filled.
"""
warnings.warn(
"pad is deprecated and will be removed in a future version. "
"Use ffill instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.ffill(limit=limit)

@final
@Substitution(name="groupby")
def bfill(self, limit=None):
Expand All @@ -2986,31 +2961,6 @@ def bfill(self, limit=None):
"""
return self._fill("bfill", limit=limit)

def backfill(self, limit=None):
"""
Backward fill the values.

.. deprecated:: 1.4
Use bfill instead.

Parameters
----------
limit : int, optional
Limit of how many values to fill.

Returns
-------
Series or DataFrame
Object with missing values filled.
"""
warnings.warn(
"backfill is deprecated and will be removed in a future version. "
"Use bfill instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.bfill(limit=limit)

@final
@Substitution(name="groupby")
@Substitution(see_also=_common_see_also)
Expand Down
51 changes: 0 additions & 51 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final,
no_type_check,
)
import warnings

import numpy as np

Expand Down Expand Up @@ -50,7 +49,6 @@
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.generic import (
ABCDataFrame,
Expand Down Expand Up @@ -562,30 +560,6 @@ def ffill(self, limit=None):
"""
return self._upsample("ffill", limit=limit)

def pad(self, limit=None):
"""
Forward fill the values.

.. deprecated:: 1.4
Use ffill instead.

Parameters
----------
limit : int, optional
Limit of how many values to fill.

Returns
-------
An upsampled Series.
"""
warnings.warn(
"pad is deprecated and will be removed in a future version. "
"Use ffill instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.ffill(limit=limit)

def nearest(self, limit=None):
"""
Resample by using the nearest value.
Expand Down Expand Up @@ -748,31 +722,6 @@ def bfill(self, limit=None):
"""
return self._upsample("bfill", limit=limit)

def backfill(self, limit=None):
"""
Backward fill the values.

.. deprecated:: 1.4
Use bfill instead.

Parameters
----------
limit : int, optional
Limit of how many values to fill.

Returns
-------
Series, DataFrame
An upsampled Series or DataFrame with backward filled NaN values.
"""
warnings.warn(
"backfill is deprecated and will be removed in a future version. "
"Use bfill instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.bfill(limit=limit)

def fillna(self, method, limit=None):
"""
Fill missing values introduced by upsampling.
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/groupby/test_allowlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ def test_tab_completion(mframe):
"idxmin",
"ffill",
"bfill",
"pad",
"backfill",
"rolling",
"expanding",
"pipe",
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,15 +2778,6 @@ def test_rolling_wrong_param_min_period():
test_df.groupby("name")["val"].rolling(window=2, min_period=1).sum()


def test_pad_backfill_deprecation():
# GH 33396
s = Series([1, 2, 3])
with tm.assert_produces_warning(FutureWarning, match="backfill"):
s.groupby(level=0).backfill()
with tm.assert_produces_warning(FutureWarning, match="pad"):
s.groupby(level=0).pad()


def test_by_column_values_with_same_starting_value():
# GH29635
df = DataFrame(
Expand Down
9 changes: 0 additions & 9 deletions pandas/tests/resample/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,3 @@ def test_interpolate_posargs_deprecation():

expected.index._data.freq = "3s"
tm.assert_series_equal(result, expected)


def test_pad_backfill_deprecation():
# GH 33396
s = Series([1, 2, 3], index=date_range("20180101", periods=3, freq="h"))
with tm.assert_produces_warning(FutureWarning, match="backfill"):
s.resample("30min").backfill()
with tm.assert_produces_warning(FutureWarning, match="pad"):
s.resample("30min").pad()