Skip to content

Commit 6527d76

Browse files
author
tp
committed
Remove freq keyword from df.rolling() etc.
1 parent 2c903d5 commit 6527d76

File tree

5 files changed

+63
-132
lines changed

5 files changed

+63
-132
lines changed

doc/source/whatsnew/v0.22.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ Removal of prior version deprecations/changes
150150
- ``pd.tseries.util.isleapyear`` has been removed (deprecated since v0.19). Use ``.is_leap_year`` property in Datetime-likes instead (:issue:`18370`)
151151
- ``pd.ordered_merge`` has been removed (deprecated since v0.19). Use ``pd.merge_ordered`` instead (:issue:`18459`)
152152
- The ``SparseList`` class has been removed (:issue:`14007`)
153+
- The ``freq`` parameter has been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
154+
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601)
153155

154156
.. _whatsnew_0220.performance:
155157

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

+26-56
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
@@ -506,6 +483,11 @@ class Window(_Window):
506483
If ``win_type=None`` all points are evenly weighted. To learn more about
507484
different window types see `scipy.signal window functions
508485
<https://docs.scipy.org/doc/scipy/reference/signal.html#window-functions>`__.
486+
487+
See Also
488+
--------
489+
expanding : Provides expanding transformations.
490+
ewm : Provides exponential weighted functions
509491
"""
510492

511493
def validate(self):
@@ -876,8 +858,6 @@ def sum(self, *args, **kwargs):
876858

877859
def max(self, how=None, *args, **kwargs):
878860
nv.validate_window_func('max', args, kwargs)
879-
if self.freq is not None and how is None:
880-
how = 'max'
881861
return self._apply('roll_max', 'max', how=how, **kwargs)
882862

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

892872
def min(self, how=None, *args, **kwargs):
893873
nv.validate_window_func('min', args, kwargs)
894-
if self.freq is not None and how is None:
895-
how = 'min'
896874
return self._apply('roll_min', 'min', how=how, **kwargs)
897875

898876
def mean(self, *args, **kwargs):
@@ -909,8 +887,6 @@ def mean(self, *args, **kwargs):
909887
Method for down- or re-sampling""")
910888

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

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

10611037
def _get_corr(a, b):
10621038
a = a.rolling(window=window, min_periods=self.min_periods,
1063-
freq=self.freq, center=self.center)
1039+
center=self.center)
10641040
b = b.rolling(window=window, min_periods=self.min_periods,
1065-
freq=self.freq, center=self.center)
1041+
center=self.center)
10661042

10671043
return a.cov(b, **kwargs) / (a.std(**kwargs) * b.std(**kwargs))
10681044

@@ -1136,7 +1112,7 @@ def _validate_monotonic(self):
11361112
"monotonic".format(formatted))
11371113

11381114
def _validate_freq(self):
1139-
""" validate & return our freq """
1115+
""" validate & return window frequency """
11401116
from pandas.tseries.frequencies import to_offset
11411117
try:
11421118
return to_offset(self.window)
@@ -1346,10 +1322,6 @@ class Expanding(_Rolling_and_Expanding):
13461322
min_periods : int, default None
13471323
Minimum number of observations in window required to have a value
13481324
(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.
13531325
center : boolean, default False
13541326
Set the labels at the center of the window.
13551327
axis : int or string, default 0
@@ -1382,17 +1354,18 @@ class Expanding(_Rolling_and_Expanding):
13821354
By default, the result is set to the right edge of the window. This can be
13831355
changed to the center of the window by setting ``center=True``.
13841356
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`).
1357+
See Also
1358+
--------
1359+
rolling : Provides rolling window calculations
1360+
ewm : Provides exponential weighted functions
13881361
"""
13891362

1390-
_attributes = ['min_periods', 'freq', 'center', 'axis']
1363+
_attributes = ['min_periods', 'center', 'axis']
13911364

1392-
def __init__(self, obj, min_periods=1, freq=None, center=False, axis=0,
1365+
def __init__(self, obj, min_periods=1, center=False, axis=0,
13931366
**kwargs):
13941367
super(Expanding, self).__init__(obj=obj, min_periods=min_periods,
1395-
freq=freq, center=center, axis=axis)
1368+
center=center, axis=axis)
13961369

13971370
@property
13981371
def _constructor(self):
@@ -1611,9 +1584,6 @@ class EWM(_Rolling):
16111584
min_periods : int, default 0
16121585
Minimum number of observations in window required to have a value
16131586
(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
16171587
adjust : boolean, default True
16181588
Divide by decaying adjustment factor in beginning periods to account
16191589
for imbalance in relative weightings (viewing EWMA as a moving average)
@@ -1651,10 +1621,6 @@ class EWM(_Rolling):
16511621
parameter descriptions above; see the link at the end of this section for
16521622
a detailed explanation.
16531623
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-
16581624
When adjust is True (default), weighted averages are calculated using
16591625
weights (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1.
16601626
@@ -1674,16 +1640,20 @@ class EWM(_Rolling):
16741640
16751641
More details can be found at
16761642
http://pandas.pydata.org/pandas-docs/stable/computation.html#exponentially-weighted-windows
1643+
1644+
See Also
1645+
--------
1646+
rolling : Provides rolling window calculations
1647+
expanding : Provides expanding transformations.
16771648
"""
1678-
_attributes = ['com', 'min_periods', 'freq', 'adjust', 'ignore_na', 'axis']
1649+
_attributes = ['com', 'min_periods', 'adjust', 'ignore_na', 'axis']
16791650

16801651
def __init__(self, obj, com=None, span=None, halflife=None, alpha=None,
1681-
min_periods=0, freq=None, adjust=True, ignore_na=False,
1652+
min_periods=0, adjust=True, ignore_na=False,
16821653
axis=0):
16831654
self.obj = obj
16841655
self.com = _get_center_of_mass(com, span, halflife, alpha)
16851656
self.min_periods = min_periods
1686-
self.freq = freq
16871657
self.adjust = adjust
16881658
self.ignore_na = ignore_na
16891659
self.axis = axis

pandas/stats/moments.py

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

211+
# TODO: the below is only in place temporary until this module is removed.
212+
kwargs.pop('freq', None) # freq removed in 0.22
211213
# how is a keyword that if not-None should be in kwds
212214
how = kwargs.pop('how', None)
213215
if how is not None:
@@ -680,7 +682,6 @@ def f(arg, min_periods=1, freq=None, **kwargs):
680682
name,
681683
arg,
682684
min_periods=min_periods,
683-
freq=freq,
684685
func_kw=func_kw,
685686
**kwargs)
686687
return f

0 commit comments

Comments
 (0)