Skip to content

Commit 2f16726

Browse files
mroeschkeluckyvs1
authored andcommitted
DEPR: Rolling.win_type returning freq & is_datetimelike (pandas-dev#38963)
1 parent 2e2400c commit 2f16726

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

doc/source/whatsnew/v1.3.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Deprecations
161161
- 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`)
162162
- Deprecated keyword ``try_cast`` in :meth:`Series.where`, :meth:`Series.mask`, :meth:`DataFrame.where`, :meth:`DataFrame.mask`; cast results manually if desired (:issue:`38836`)
163163
- 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`)
164+
- Deprecated :attr:`Rolling.win_type` returning ``"freq"`` (:issue:`38963`)
165+
- Deprecated :attr:`Rolling.is_datetimelike` (:issue:`38963`)
164166
-
165167

166168
.. ---------------------------------------------------------------------------

pandas/core/groupby/base.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
import collections
77
from typing import List
8+
import warnings
89

910
from pandas._typing import final
1011

@@ -27,7 +28,10 @@ def _shallow_copy(self, obj, **kwargs):
2728
obj = obj.obj
2829
for attr in self._attributes:
2930
if attr not in kwargs:
30-
kwargs[attr] = getattr(self, attr)
31+
# TODO: Remove once win_type deprecation is enforced
32+
with warnings.catch_warnings():
33+
warnings.filterwarnings("ignore", "win_type", FutureWarning)
34+
kwargs[attr] = getattr(self, attr)
3135
return self._constructor(obj, **kwargs)
3236

3337

@@ -59,7 +63,10 @@ def _gotitem(self, key, ndim, subset=None):
5963

6064
# we need to make a shallow copy of ourselves
6165
# with the same groupby
62-
kwargs = {attr: getattr(self, attr) for attr in self._attributes}
66+
# TODO: Remove once win_type deprecation is enforced
67+
with warnings.catch_warnings():
68+
warnings.filterwarnings("ignore", "win_type", FutureWarning)
69+
kwargs = {attr: getattr(self, attr) for attr in self._attributes}
6370

6471
# Try to select from a DataFrame, falling back to a Series
6572
try:

pandas/core/window/rolling.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def __init__(
110110
self.window = window
111111
self.min_periods = min_periods
112112
self.center = center
113-
self.win_type = win_type
113+
# TODO: Change this back to self.win_type once deprecation is enforced
114+
self._win_type = win_type
114115
self.axis = obj._get_axis_number(axis) if axis is not None else None
115116
self.method = method
116117
self._win_freq_i8 = None
@@ -131,6 +132,27 @@ def __init__(
131132
)
132133
self.validate()
133134

135+
@property
136+
def win_type(self):
137+
if self._win_freq_i8 is not None:
138+
warnings.warn(
139+
"win_type will no longer return 'freq' in a future version. "
140+
"Check the type of self.window instead.",
141+
FutureWarning,
142+
stacklevel=2,
143+
)
144+
return "freq"
145+
return self._win_type
146+
147+
@property
148+
def is_datetimelike(self):
149+
warnings.warn(
150+
"is_datetimelike is deprecated and will be removed in a future version.",
151+
FutureWarning,
152+
stacklevel=2,
153+
)
154+
return self._win_freq_i8 is not None
155+
134156
def validate(self) -> None:
135157
if self.center is not None and not is_bool(self.center):
136158
raise ValueError("center must be a boolean")

pandas/tests/window/test_api.py

+6
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,9 @@ def test_multiple_agg_funcs(func, window_size, expected_vals):
319319
result = window.agg({"low": ["mean", "max"], "high": ["mean", "min"]})
320320

321321
tm.assert_frame_equal(result, expected)
322+
323+
324+
def test_is_datetimelike_deprecated():
325+
s = Series(range(1)).rolling(1)
326+
with tm.assert_produces_warning(FutureWarning):
327+
assert not s.is_datetimelike

pandas/tests/window/test_win_type.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pandas.errors import UnsupportedFunctionCall
55
import pandas.util._test_decorators as td
66

7-
from pandas import DataFrame, Series, Timedelta, concat
7+
from pandas import DataFrame, Series, Timedelta, concat, date_range
88
import pandas._testing as tm
99
from pandas.api.indexers import BaseIndexer
1010

@@ -137,6 +137,12 @@ def test_consistent_win_type_freq(arg):
137137
s.rolling(arg, win_type="freq")
138138

139139

140+
def test_win_type_freq_return_deprecation():
141+
freq_roll = Series(range(2), index=date_range("2020", periods=2)).rolling("2s")
142+
with tm.assert_produces_warning(FutureWarning):
143+
assert freq_roll.win_type == "freq"
144+
145+
140146
@td.skip_if_no_scipy
141147
def test_win_type_not_implemented():
142148
class CustomIndexer(BaseIndexer):

0 commit comments

Comments
 (0)