Skip to content

Commit 010cf95

Browse files
author
tp
committed
Remove freq keyword from df.rolling() etc.
1 parent d163de7 commit 010cf95

File tree

5 files changed

+48
-132
lines changed

5 files changed

+48
-132
lines changed

doc/source/whatsnew/v0.22.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ Removal of prior version deprecations/changes
133133
- ``pd.tseries.util.pivot_annual`` has been removed (deprecated since v0.19). Use ``pivot_table`` instead (:issue:`18370`)
134134
- ``pd.tseries.util.isleapyear`` has been removed (deprecated since v0.19). Use ``.is_leap_year`` property in Datetime-likes instead (:issue:`18370`)
135135
- ``pd.ordered_merge`` has been removed (deprecated since v0.19). Use ``pd.merge_ordered`` instead (:issue:`18459`)
136+
- The ``freq`` parameter has been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
137+
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601)
136138

137139
.. _whatsnew_0220.performance:
138140

pandas/core/generic.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -7357,31 +7357,31 @@ def _add_series_or_dataframe_operations(cls):
73577357
from pandas.core import window as rwindow
73587358

73597359
@Appender(rwindow.rolling.__doc__)
7360-
def rolling(self, window, min_periods=None, freq=None, center=False,
7360+
def rolling(self, window, min_periods=None, center=False,
73617361
win_type=None, on=None, axis=0, closed=None):
73627362
axis = self._get_axis_number(axis)
73637363
return rwindow.rolling(self, window=window,
7364-
min_periods=min_periods, freq=freq,
7364+
min_periods=min_periods,
73657365
center=center, win_type=win_type,
73667366
on=on, axis=axis, closed=closed)
73677367

73687368
cls.rolling = rolling
73697369

73707370
@Appender(rwindow.expanding.__doc__)
7371-
def expanding(self, min_periods=1, freq=None, center=False, axis=0):
7371+
def expanding(self, min_periods=1, center=False, axis=0):
73727372
axis = self._get_axis_number(axis)
7373-
return rwindow.expanding(self, min_periods=min_periods, freq=freq,
7373+
return rwindow.expanding(self, min_periods=min_periods,
73747374
center=center, axis=axis)
73757375

73767376
cls.expanding = expanding
73777377

73787378
@Appender(rwindow.ewm.__doc__)
73797379
def ewm(self, com=None, span=None, halflife=None, alpha=None,
7380-
min_periods=0, freq=None, adjust=True, ignore_na=False,
7380+
min_periods=0, adjust=True, ignore_na=False,
73817381
axis=0):
73827382
axis = self._get_axis_number(axis)
73837383
return rwindow.ewm(self, com=com, span=span, halflife=halflife,
7384-
alpha=alpha, min_periods=min_periods, freq=freq,
7384+
alpha=alpha, min_periods=min_periods,
73857385
adjust=adjust, ignore_na=ignore_na, axis=axis)
73867386

73877387
cls.ewm = ewm

pandas/core/window.py

+12-57
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,21 @@
5858

5959

6060
class _Window(PandasObject, SelectionMixin):
61-
_attributes = ['window', 'min_periods', 'freq', 'center', 'win_type',
61+
_attributes = ['window', 'min_periods', 'center', 'win_type',
6262
'axis', 'on', 'closed']
6363
exclusions = set()
6464

65-
def __init__(self, obj, window=None, min_periods=None, freq=None,
65+
def __init__(self, obj, window=None, min_periods=None,
6666
center=False, win_type=None, axis=0, on=None, closed=None,
6767
**kwargs):
6868

69-
if freq is not None:
70-
warnings.warn("The freq kw is deprecated and will be removed in a "
71-
"future version. You can resample prior to passing "
72-
"to a window function", FutureWarning, stacklevel=3)
73-
7469
self.__dict__.update(kwargs)
7570
self.blocks = []
7671
self.obj = obj
7772
self.on = on
7873
self.closed = closed
7974
self.window = window
8075
self.min_periods = min_periods
81-
self.freq = freq
8276
self.center = center
8377
self.win_type = win_type
8478
self.win_freq = None
@@ -117,16 +111,6 @@ def _convert_freq(self, how=None):
117111

118112
obj = self._selected_obj
119113
index = None
120-
if (self.freq is not None and
121-
isinstance(obj, (ABCSeries, ABCDataFrame))):
122-
if how is not None:
123-
warnings.warn("The how kw argument is deprecated and removed "
124-
"in a future version. You can resample prior "
125-
"to passing to a window function", FutureWarning,
126-
stacklevel=6)
127-
128-
obj = obj.resample(self.freq).aggregate(how or 'asfreq')
129-
130114
return obj, index
131115

132116
def _create_blocks(self, how):
@@ -374,14 +358,11 @@ class Window(_Window):
374358
Minimum number of observations in window required to have a value
375359
(otherwise result is NA). For a window that is specified by an offset,
376360
this will default to 1.
377-
freq : string or DateOffset object, optional (default None)
378-
.. deprecated:: 0.18.0
379-
Frequency to conform the data to before computing the statistic.
380-
Specified as a frequency string or DateOffset object.
381361
center : boolean, default False
382362
Set the labels at the center of the window.
383363
win_type : string, default None
384-
Provide a window type. See the notes below.
364+
Provide a window type. If ``None``, all points are evenly weighted.
365+
See the notes below for further information.
385366
on : string, optional
386367
For a DataFrame, column on which to calculate
387368
the rolling window, rather than the index
@@ -479,10 +460,6 @@ class Window(_Window):
479460
By default, the result is set to the right edge of the window. This can be
480461
changed to the center of the window by setting ``center=True``.
481462
482-
The `freq` keyword is used to conform time series data to a specified
483-
frequency by resampling the data. This is done with the default parameters
484-
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).
485-
486463
To learn more about the offsets & frequency strings, please see `this link
487464
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
488465
@@ -876,8 +853,6 @@ def sum(self, *args, **kwargs):
876853

877854
def max(self, how=None, *args, **kwargs):
878855
nv.validate_window_func('max', args, kwargs)
879-
if self.freq is not None and how is None:
880-
how = 'max'
881856
return self._apply('roll_max', 'max', how=how, **kwargs)
882857

883858
_shared_docs['min'] = dedent("""
@@ -891,8 +866,6 @@ def max(self, how=None, *args, **kwargs):
891866

892867
def min(self, how=None, *args, **kwargs):
893868
nv.validate_window_func('min', args, kwargs)
894-
if self.freq is not None and how is None:
895-
how = 'min'
896869
return self._apply('roll_min', 'min', how=how, **kwargs)
897870

898871
def mean(self, *args, **kwargs):
@@ -909,8 +882,6 @@ def mean(self, *args, **kwargs):
909882
Method for down- or re-sampling""")
910883

911884
def median(self, how=None, **kwargs):
912-
if self.freq is not None and how is None:
913-
how = 'median'
914885
return self._apply('roll_median_c', 'median', how=how, **kwargs)
915886

916887
_shared_docs['std'] = dedent("""
@@ -1060,9 +1031,9 @@ def corr(self, other=None, pairwise=None, **kwargs):
10601031

10611032
def _get_corr(a, b):
10621033
a = a.rolling(window=window, min_periods=self.min_periods,
1063-
freq=self.freq, center=self.center)
1034+
center=self.center)
10641035
b = b.rolling(window=window, min_periods=self.min_periods,
1065-
freq=self.freq, center=self.center)
1036+
center=self.center)
10661037

10671038
return a.cov(b, **kwargs) / (a.std(**kwargs) * b.std(**kwargs))
10681039

@@ -1136,7 +1107,7 @@ def _validate_monotonic(self):
11361107
"monotonic".format(formatted))
11371108

11381109
def _validate_freq(self):
1139-
""" validate & return our freq """
1110+
""" validate & return window frequency """
11401111
from pandas.tseries.frequencies import to_offset
11411112
try:
11421113
return to_offset(self.window)
@@ -1346,10 +1317,6 @@ class Expanding(_Rolling_and_Expanding):
13461317
min_periods : int, default None
13471318
Minimum number of observations in window required to have a value
13481319
(otherwise result is NA).
1349-
freq : string or DateOffset object, optional (default None)
1350-
.. deprecated:: 0.18.0
1351-
Frequency to conform the data to before computing the statistic.
1352-
Specified as a frequency string or DateOffset object.
13531320
center : boolean, default False
13541321
Set the labels at the center of the window.
13551322
axis : int or string, default 0
@@ -1381,18 +1348,14 @@ class Expanding(_Rolling_and_Expanding):
13811348
-----
13821349
By default, the result is set to the right edge of the window. This can be
13831350
changed to the center of the window by setting ``center=True``.
1384-
1385-
The `freq` keyword is used to conform time series data to a specified
1386-
frequency by resampling the data. This is done with the default parameters
1387-
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).
13881351
"""
13891352

1390-
_attributes = ['min_periods', 'freq', 'center', 'axis']
1353+
_attributes = ['min_periods', 'center', 'axis']
13911354

1392-
def __init__(self, obj, min_periods=1, freq=None, center=False, axis=0,
1355+
def __init__(self, obj, min_periods=1, center=False, axis=0,
13931356
**kwargs):
13941357
super(Expanding, self).__init__(obj=obj, min_periods=min_periods,
1395-
freq=freq, center=center, axis=axis)
1358+
center=center, axis=axis)
13961359

13971360
@property
13981361
def _constructor(self):
@@ -1611,9 +1574,6 @@ class EWM(_Rolling):
16111574
min_periods : int, default 0
16121575
Minimum number of observations in window required to have a value
16131576
(otherwise result is NA).
1614-
freq : None or string alias / date offset object, default=None
1615-
.. deprecated:: 0.18.0
1616-
Frequency to conform to before computing statistic
16171577
adjust : boolean, default True
16181578
Divide by decaying adjustment factor in beginning periods to account
16191579
for imbalance in relative weightings (viewing EWMA as a moving average)
@@ -1651,10 +1611,6 @@ class EWM(_Rolling):
16511611
parameter descriptions above; see the link at the end of this section for
16521612
a detailed explanation.
16531613
1654-
The `freq` keyword is used to conform time series data to a specified
1655-
frequency by resampling the data. This is done with the default parameters
1656-
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).
1657-
16581614
When adjust is True (default), weighted averages are calculated using
16591615
weights (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1.
16601616
@@ -1675,15 +1631,14 @@ class EWM(_Rolling):
16751631
More details can be found at
16761632
http://pandas.pydata.org/pandas-docs/stable/computation.html#exponentially-weighted-windows
16771633
"""
1678-
_attributes = ['com', 'min_periods', 'freq', 'adjust', 'ignore_na', 'axis']
1634+
_attributes = ['com', 'min_periods', 'adjust', 'ignore_na', 'axis']
16791635

16801636
def __init__(self, obj, com=None, span=None, halflife=None, alpha=None,
1681-
min_periods=0, freq=None, adjust=True, ignore_na=False,
1637+
min_periods=0, adjust=True, ignore_na=False,
16821638
axis=0):
16831639
self.obj = obj
16841640
self.com = _get_center_of_mass(com, span, halflife, alpha)
16851641
self.min_periods = min_periods
1686-
self.freq = freq
16871642
self.adjust = adjust
16881643
self.ignore_na = ignore_na
16891644
self.axis = axis

pandas/stats/moments.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def ensure_compat(dispatch, name, arg, func_kw=None, *args, **kwargs):
208208
if value is not None:
209209
kwds[k] = value
210210

211+
kwargs.pop('freq', None) # freq removed in 0.22
211212
# how is a keyword that if not-None should be in kwds
212213
how = kwargs.pop('how', None)
213214
if how is not None:
@@ -680,7 +681,6 @@ def f(arg, min_periods=1, freq=None, **kwargs):
680681
name,
681682
arg,
682683
min_periods=min_periods,
683-
freq=freq,
684684
func_kw=func_kw,
685685
**kwargs)
686686
return f

0 commit comments

Comments
 (0)