From 9c30f538085c35b71f0cd3a7f72c78082376bea7 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:28:51 -0700 Subject: [PATCH 1/4] DEPR: Enforce Rolling.validate/is_datetimelike/win_type deprecation --- pandas/core/window/rolling.py | 37 ++------------------------------- pandas/tests/window/test_api.py | 12 ----------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 3225b9c0d2174..5c80e43567269 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -141,8 +141,7 @@ def __init__( self.window = window self.min_periods = min_periods self.center = center - # TODO(2.0): Change this back to self.win_type once deprecation is enforced - self._win_type = win_type + self.win_type = win_type self.axis = obj._get_axis_number(axis) if axis is not None else None self.method = method self._win_freq_i8: int | None = None @@ -165,35 +164,6 @@ def __init__( self._selection = selection self._validate() - @property - def win_type(self): - if self._win_freq_i8 is not None: - warnings.warn( - "win_type will no longer return 'freq' in a future version. " - "Check the type of self.window instead.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return "freq" - return self._win_type - - @property - def is_datetimelike(self) -> bool: - warnings.warn( - "is_datetimelike is deprecated and will be removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return self._win_freq_i8 is not None - - def validate(self) -> None: - warnings.warn( - "validate is deprecated and will be removed in a future version.", - FutureWarning, - stacklevel=find_stack_level(inspect.currentframe()), - ) - return self._validate() - def _validate(self) -> None: if self.center is not None and not is_bool(self.center): raise ValueError("center must be a boolean") @@ -331,10 +301,7 @@ def _gotitem(self, key, ndim, subset=None): # we need to make a shallow copy of ourselves # with the same groupby - with warnings.catch_warnings(): - # TODO(2.0): Remove once win_type deprecation is enforced - warnings.filterwarnings("ignore", "win_type", FutureWarning) - kwargs = {attr: getattr(self, attr) for attr in self._attributes} + kwargs = {attr: getattr(self, attr) for attr in self._attributes} selection = None if subset.ndim == 2 and ( diff --git a/pandas/tests/window/test_api.py b/pandas/tests/window/test_api.py index 6495f7411938c..d55e398acf992 100644 --- a/pandas/tests/window/test_api.py +++ b/pandas/tests/window/test_api.py @@ -340,18 +340,6 @@ def test_multiple_agg_funcs(func, window_size, expected_vals): tm.assert_frame_equal(result, expected) -def test_is_datetimelike_deprecated(): - s = Series(range(1)).rolling(1) - with tm.assert_produces_warning(FutureWarning): - assert not s.is_datetimelike - - -def test_validate_deprecated(): - s = Series(range(1)).rolling(1) - with tm.assert_produces_warning(FutureWarning): - assert s.validate() is None - - @pytest.mark.filterwarnings("ignore:min_periods:FutureWarning") def test_dont_modify_attributes_after_methods( arithmetic_win_operators, closed, center, min_periods, step From d3da59c00e0c064de64290a8448e3a331c4dbcdb Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 28 Sep 2022 11:37:02 -0700 Subject: [PATCH 2/4] Remove another test --- pandas/tests/window/test_win_type.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/tests/window/test_win_type.py b/pandas/tests/window/test_win_type.py index ba80ac19a6b6a..9bf5ba816c272 100644 --- a/pandas/tests/window/test_win_type.py +++ b/pandas/tests/window/test_win_type.py @@ -9,7 +9,6 @@ Series, Timedelta, concat, - date_range, ) import pandas._testing as tm from pandas.api.indexers import BaseIndexer @@ -168,12 +167,6 @@ def test_consistent_win_type_freq(arg): s.rolling(arg, win_type="freq") -def test_win_type_freq_return_deprecation(): - freq_roll = Series(range(2), index=date_range("2020", periods=2)).rolling("2s") - with tm.assert_produces_warning(FutureWarning): - assert freq_roll.win_type == "freq" - - @td.skip_if_no_scipy def test_win_type_not_implemented(): class CustomIndexer(BaseIndexer): From 7c84c82382f4107a536355eda02c34f954a7f905 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:53:51 -0700 Subject: [PATCH 3/4] turn test into assertion --- pandas/tests/window/test_win_type.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/tests/window/test_win_type.py b/pandas/tests/window/test_win_type.py index 27ed8e2937f37..b5206d802776b 100644 --- a/pandas/tests/window/test_win_type.py +++ b/pandas/tests/window/test_win_type.py @@ -9,6 +9,7 @@ Series, Timedelta, concat, + date_range, ) import pandas._testing as tm from pandas.api.indexers import BaseIndexer @@ -167,6 +168,12 @@ def test_consistent_win_type_freq(arg): s.rolling(arg, win_type="freq") +def test_win_type_freq_return_none(): + # GH 48838 + freq_roll = Series(range(2), index=date_range("2020", periods=2)).rolling("2s") + assert freq_roll.win_type is None + + @td.skip_if_no_scipy def test_win_type_not_implemented(): class CustomIndexer(BaseIndexer): From 1f137d70ec4cf5687af73afa53d3ebd43404d68f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 19 Oct 2022 10:55:56 -0700 Subject: [PATCH 4/4] Add whatsnew --- doc/source/whatsnew/v2.0.0.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 596c16a5b3621..1e4fb11df3314 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -145,6 +145,9 @@ Deprecations Removal of prior version deprecations/changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`) +- Removed :meth:`.Rolling.validate`, :meth:`.Expanding.validate`, and :meth:`.ExponentialMovingWindow.validate` (:issue:`43665`) +- Removed :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) +- Removed :attr:`Rolling.is_datetimelike` (:issue:`38963`) - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) .. ---------------------------------------------------------------------------