From 88630636bd811ae4135069bbc159ab5514e80335 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:41:33 -0700 Subject: [PATCH 1/5] Enforce expanding(center) deprecation --- pandas/core/generic.py | 11 +---------- pandas/core/window/expanding.py | 11 +---------- pandas/tests/window/test_expanding.py | 13 ------------- 3 files changed, 2 insertions(+), 33 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f192d89bac545..7c1cefae98093 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -12089,17 +12089,8 @@ def expanding( method: str = "single", ) -> Expanding: axis = self._get_axis_number(axis) - if center is not None: - warnings.warn( - "The `center` argument on `expanding` will be removed in the future.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - else: - center = False - return Expanding( - self, min_periods=min_periods, center=center, axis=axis, method=method + self, min_periods=min_periods, center=False, axis=axis, method=method ) @final diff --git a/pandas/core/window/expanding.py b/pandas/core/window/expanding.py index e997ffe1ec132..621f1ae18080d 100644 --- a/pandas/core/window/expanding.py +++ b/pandas/core/window/expanding.py @@ -55,13 +55,6 @@ class Expanding(RollingAndExpandingMixin): Minimum number of observations in window required to have a value; otherwise, result is ``np.nan``. - center : bool, default False - If False, set the window labels as the right edge of the window index. - - If True, set the window labels as the center of the window index. - - .. deprecated:: 1.1.0 - axis : int or str, default 0 If ``0`` or ``'index'``, roll across the rows. @@ -123,13 +116,12 @@ class Expanding(RollingAndExpandingMixin): 4 7.0 """ - _attributes: list[str] = ["min_periods", "center", "axis", "method"] + _attributes: list[str] = ["min_periods", "axis", "method"] def __init__( self, obj: NDFrame, min_periods: int = 1, - center: bool | None = None, axis: Axis = 0, method: str = "single", selection=None, @@ -137,7 +129,6 @@ def __init__( super().__init__( obj=obj, min_periods=min_periods, - center=center, axis=axis, method=method, selection=selection, diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index a12997018052d..d54e3f6b0d55d 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -241,19 +241,6 @@ def test_iter_expanding_series(ser, expected, min_periods): tm.assert_series_equal(actual, expected) -def test_center_deprecate_warning(): - # GH 20647 - df = DataFrame() - with tm.assert_produces_warning(FutureWarning): - df.expanding(center=True) - - with tm.assert_produces_warning(FutureWarning): - df.expanding(center=False) - - with tm.assert_produces_warning(None): - df.expanding() - - def test_expanding_sem(frame_or_series): # GH: 26476 obj = frame_or_series([0, 1, 2]) From 3e5737ea41ff130903de42d2ca8c1553d6a505e9 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Sep 2022 17:33:16 -0700 Subject: [PATCH 2/5] Fix tests --- pandas/core/generic.py | 5 +---- pandas/tests/window/test_expanding.py | 12 ------------ 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7c1cefae98093..280650dfee5c6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -12084,14 +12084,11 @@ def rolling( def expanding( self, min_periods: int = 1, - center: bool_t | None = None, axis: Axis = 0, method: str = "single", ) -> Expanding: axis = self._get_axis_number(axis) - return Expanding( - self, min_periods=min_periods, center=False, axis=axis, method=method - ) + return Expanding(self, min_periods=min_periods, axis=axis, method=method) @final @doc(ExponentialMovingWindow) diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index d54e3f6b0d55d..53abf58bc91fb 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -23,9 +23,6 @@ def test_doc_string(): df.expanding(2).sum() -@pytest.mark.filterwarnings( - "ignore:The `center` argument on `expanding` will be removed in the future" -) def test_constructor(frame_or_series): # GH 12669 @@ -33,14 +30,9 @@ def test_constructor(frame_or_series): # valid c(min_periods=1) - c(min_periods=1, center=True) - c(min_periods=1, center=False) @pytest.mark.parametrize("w", [2.0, "foo", np.array([2])]) -@pytest.mark.filterwarnings( - "ignore:The `center` argument on `expanding` will be removed in the future" -) def test_constructor_invalid(frame_or_series, w): # not valid @@ -49,10 +41,6 @@ def test_constructor_invalid(frame_or_series, w): with pytest.raises(ValueError, match=msg): c(min_periods=w) - msg = "center must be a boolean" - with pytest.raises(ValueError, match=msg): - c(min_periods=1, center=w) - @pytest.mark.parametrize("method", ["std", "mean", "sum", "max", "min", "var"]) def test_numpy_compat(method): From 72b1b4bafa3e7a954dcf556a038de37f96f7b5a4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:48:00 -0700 Subject: [PATCH 3/5] change test to raises --- pandas/tests/window/test_expanding.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/window/test_expanding.py b/pandas/tests/window/test_expanding.py index 53abf58bc91fb..8417c6dd8419c 100644 --- a/pandas/tests/window/test_expanding.py +++ b/pandas/tests/window/test_expanding.py @@ -229,6 +229,13 @@ def test_iter_expanding_series(ser, expected, min_periods): tm.assert_series_equal(actual, expected) +def test_center_invalid(): + # GH 20647 + df = DataFrame() + with pytest.raises(TypeError, match=".* got an unexpected keyword"): + df.expanding(center=True) + + def test_expanding_sem(frame_or_series): # GH: 26476 obj = frame_or_series([0, 1, 2]) From abd2e1e5567668a8887ab60fc9ac7fb3c41c69ea Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 19 Oct 2022 11:08:39 -0700 Subject: [PATCH 4/5] add whatsnew --- doc/source/whatsnew/v2.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 596c16a5b3621..3771887435845 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -146,6 +146,7 @@ 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`) +- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`) .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: From edbf3c22e92caafc58bbf25c7c8b00cb328c08fd Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:31:32 -0700 Subject: [PATCH 5/5] Remove artifact --- doc/source/whatsnew/v2.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 41b705c1ec92e..a2a0812429050 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -149,7 +149,6 @@ Removal of prior version deprecations/changes - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) - Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`) - Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`) ->>>>>>> upstream/main .. --------------------------------------------------------------------------- .. _whatsnew_200.performance: