From d0167115548765f185a7041bafcca5fab39adda8 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 14 Oct 2022 11:29:26 +0200 Subject: [PATCH 1/3] DEP: Enforce deprecation of pad/backfill for groupby and resample --- doc/source/reference/groupby.rst | 4 -- doc/source/reference/resampling.rst | 2 - pandas/core/groupby/base.py | 2 - pandas/core/groupby/groupby.py | 50 ----------------------- pandas/core/resample.py | 51 ------------------------ pandas/tests/groupby/test_allowlist.py | 2 - pandas/tests/resample/test_deprecated.py | 9 ----- 7 files changed, 120 deletions(-) diff --git a/doc/source/reference/groupby.rst b/doc/source/reference/groupby.rst index 138018eacef49..7c6bf485c0599 100644 --- a/doc/source/reference/groupby.rst +++ b/doc/source/reference/groupby.rst @@ -65,7 +65,6 @@ Function application DataFrameGroupBy.all DataFrameGroupBy.any - DataFrameGroupBy.backfill DataFrameGroupBy.bfill DataFrameGroupBy.corr DataFrameGroupBy.corrwith @@ -94,7 +93,6 @@ Function application DataFrameGroupBy.nth DataFrameGroupBy.nunique DataFrameGroupBy.ohlc - DataFrameGroupBy.pad DataFrameGroupBy.pct_change DataFrameGroupBy.prod DataFrameGroupBy.quantile @@ -120,7 +118,6 @@ Function application SeriesGroupBy.all SeriesGroupBy.any - SeriesGroupBy.backfill SeriesGroupBy.bfill SeriesGroupBy.corr SeriesGroupBy.count @@ -153,7 +150,6 @@ Function application SeriesGroupBy.nunique SeriesGroupBy.unique SeriesGroupBy.ohlc - SeriesGroupBy.pad SeriesGroupBy.pct_change SeriesGroupBy.prod SeriesGroupBy.quantile diff --git a/doc/source/reference/resampling.rst b/doc/source/reference/resampling.rst index 57263139d9c18..e0228481e6ed4 100644 --- a/doc/source/reference/resampling.rst +++ b/doc/source/reference/resampling.rst @@ -35,9 +35,7 @@ Upsampling :toctree: api/ Resampler.ffill - Resampler.backfill Resampler.bfill - Resampler.pad Resampler.nearest Resampler.fillna Resampler.asfreq diff --git a/pandas/core/groupby/base.py b/pandas/core/groupby/base.py index 953fc4673a38e..a953dab2115da 100644 --- a/pandas/core/groupby/base.py +++ b/pandas/core/groupby/base.py @@ -73,7 +73,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]: transformation_kernels = frozenset( [ - "backfill", "bfill", "cumcount", "cummax", @@ -84,7 +83,6 @@ def maybe_normalize_deprecated_kernels(kernel) -> Literal["bfill", "ffill"]: "ffill", "fillna", "ngroup", - "pad", "pct_change", "rank", "shift", diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index e79753f215769..8c637901e720f 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -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): @@ -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) diff --git a/pandas/core/resample.py b/pandas/core/resample.py index f821f8c7b6bd5..f64ca90537b3f 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -11,7 +11,6 @@ final, no_type_check, ) -import warnings import numpy as np @@ -50,7 +49,6 @@ deprecate_nonkeyword_arguments, doc, ) -from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.generic import ( ABCDataFrame, @@ -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. @@ -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. diff --git a/pandas/tests/groupby/test_allowlist.py b/pandas/tests/groupby/test_allowlist.py index b9a7bb271e948..93df7d1f1d4a0 100644 --- a/pandas/tests/groupby/test_allowlist.py +++ b/pandas/tests/groupby/test_allowlist.py @@ -217,8 +217,6 @@ def test_tab_completion(mframe): "idxmin", "ffill", "bfill", - "pad", - "backfill", "rolling", "expanding", "pipe", diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index 126ca05ca1546..3aac7a961fa19 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -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() From 7f2b9496f62ffeee02d4002dbb37551e56f46266 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Fri, 14 Oct 2022 12:20:00 +0200 Subject: [PATCH 2/3] Remove test --- pandas/tests/groupby/test_groupby.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index a1648fd6fdfc3..8439e4b8c9a00 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -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( From 595651779705933556a123c46769a2800b2cd1ac Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Wed, 19 Oct 2022 09:36:38 +0100 Subject: [PATCH 3/3] Add whatsnew --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 80c8ad9a8b2eb..d8420edbefc7c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -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: