diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 38b7a1d13c253..d35965ead1a1c 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -161,6 +161,8 @@ Deprecations - Deprecated :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` as a public methods, users should use :meth:`MultiIndex.is_monotonic_increasing` instead (:issue:`32259`) - Deprecated keyword ``try_cast`` in :meth:`Series.where`, :meth:`Series.mask`, :meth:`DataFrame.where`, :meth:`DataFrame.mask`; cast results manually if desired (:issue:`38836`) - Deprecated comparison of :class:`Timestamp` object with ``datetime.date`` objects. Instead of e.g. ``ts <= mydate`` use ``ts <= pd.Timestamp(mydate)`` or ``ts.date() <= mydate`` (:issue:`36131`) +- Deprecated :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`) +- Deprecated :attr:`Rolling.is_datetimelike` (:issue:`38963`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/groupby/base.py b/pandas/core/groupby/base.py index 99426c55da29b..594c5899209df 100644 --- a/pandas/core/groupby/base.py +++ b/pandas/core/groupby/base.py @@ -5,6 +5,7 @@ """ import collections from typing import List +import warnings from pandas._typing import final @@ -27,7 +28,10 @@ def _shallow_copy(self, obj, **kwargs): obj = obj.obj for attr in self._attributes: if attr not in kwargs: - kwargs[attr] = getattr(self, attr) + # TODO: Remove once win_type deprecation is enforced + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "win_type", FutureWarning) + kwargs[attr] = getattr(self, attr) return self._constructor(obj, **kwargs) @@ -59,7 +63,10 @@ def _gotitem(self, key, ndim, subset=None): # we need to make a shallow copy of ourselves # with the same groupby - kwargs = {attr: getattr(self, attr) for attr in self._attributes} + # TODO: Remove once win_type deprecation is enforced + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "win_type", FutureWarning) + kwargs = {attr: getattr(self, attr) for attr in self._attributes} # Try to select from a DataFrame, falling back to a Series try: diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 7ae1e61d426b9..a4612a4c8ed5d 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -110,7 +110,8 @@ def __init__( self.window = window self.min_periods = min_periods self.center = center - self.win_type = win_type + # TODO: Change this back to self.win_type once deprecation is enforced + 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 = None @@ -131,6 +132,27 @@ def __init__( ) 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=2, + ) + return "freq" + return self._win_type + + @property + def is_datetimelike(self): + warnings.warn( + "is_datetimelike is deprecated and will be removed in a future version.", + FutureWarning, + stacklevel=2, + ) + return self._win_freq_i8 is not None + def validate(self) -> None: if self.center is not None and not is_bool(self.center): raise ValueError("center must be a boolean") diff --git a/pandas/tests/window/test_api.py b/pandas/tests/window/test_api.py index 52c629f96b713..7d3c29dc60be0 100644 --- a/pandas/tests/window/test_api.py +++ b/pandas/tests/window/test_api.py @@ -319,3 +319,9 @@ def test_multiple_agg_funcs(func, window_size, expected_vals): result = window.agg({"low": ["mean", "max"], "high": ["mean", "min"]}) 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 diff --git a/pandas/tests/window/test_win_type.py b/pandas/tests/window/test_win_type.py index 4b1028e165c80..1cfba6f020018 100644 --- a/pandas/tests/window/test_win_type.py +++ b/pandas/tests/window/test_win_type.py @@ -4,7 +4,7 @@ from pandas.errors import UnsupportedFunctionCall import pandas.util._test_decorators as td -from pandas import DataFrame, Series, Timedelta, concat +from pandas import DataFrame, Series, Timedelta, concat, date_range import pandas._testing as tm from pandas.api.indexers import BaseIndexer @@ -137,6 +137,12 @@ 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):