Skip to content

DEPR/CLN: Remove freq parameters from df.rolling/expanding/ewm #18601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ Removal of prior version deprecations/changes
- The ``SparseList`` class has been removed (:issue:`14007`)
- The ``pandas.io.wb`` and ``pandas.io.data`` stub modules have been removed (:issue:`13735`)
- ``Categorical.from_array`` has been removed (:issue:`13854`)
- The ``freq`` parameter has been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601)

.. _whatsnew_0220.performance:

Expand Down
12 changes: 6 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7357,31 +7357,31 @@ def _add_series_or_dataframe_operations(cls):
from pandas.core import window as rwindow

@Appender(rwindow.rolling.__doc__)
def rolling(self, window, min_periods=None, freq=None, center=False,
def rolling(self, window, min_periods=None, center=False,
win_type=None, on=None, axis=0, closed=None):
axis = self._get_axis_number(axis)
return rwindow.rolling(self, window=window,
min_periods=min_periods, freq=freq,
min_periods=min_periods,
center=center, win_type=win_type,
on=on, axis=axis, closed=closed)

cls.rolling = rolling

@Appender(rwindow.expanding.__doc__)
def expanding(self, min_periods=1, freq=None, center=False, axis=0):
def expanding(self, min_periods=1, center=False, axis=0):
axis = self._get_axis_number(axis)
return rwindow.expanding(self, min_periods=min_periods, freq=freq,
return rwindow.expanding(self, min_periods=min_periods,
center=center, axis=axis)

cls.expanding = expanding

@Appender(rwindow.ewm.__doc__)
def ewm(self, com=None, span=None, halflife=None, alpha=None,
min_periods=0, freq=None, adjust=True, ignore_na=False,
min_periods=0, adjust=True, ignore_na=False,
axis=0):
axis = self._get_axis_number(axis)
return rwindow.ewm(self, com=com, span=span, halflife=halflife,
alpha=alpha, min_periods=min_periods, freq=freq,
alpha=alpha, min_periods=min_periods,
adjust=adjust, ignore_na=ignore_na, axis=axis)

cls.ewm = ewm
Expand Down
82 changes: 26 additions & 56 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,21 @@


class _Window(PandasObject, SelectionMixin):
_attributes = ['window', 'min_periods', 'freq', 'center', 'win_type',
_attributes = ['window', 'min_periods', 'center', 'win_type',
'axis', 'on', 'closed']
exclusions = set()

def __init__(self, obj, window=None, min_periods=None, freq=None,
def __init__(self, obj, window=None, min_periods=None,
center=False, win_type=None, axis=0, on=None, closed=None,
**kwargs):

if freq is not None:
warnings.warn("The freq kw is deprecated and will be removed in a "
"future version. You can resample prior to passing "
"to a window function", FutureWarning, stacklevel=3)

self.__dict__.update(kwargs)
self.blocks = []
self.obj = obj
self.on = on
self.closed = closed
self.window = window
self.min_periods = min_periods
self.freq = freq
self.center = center
self.win_type = win_type
self.win_freq = None
Expand Down Expand Up @@ -117,16 +111,6 @@ def _convert_freq(self, how=None):

obj = self._selected_obj
index = None
if (self.freq is not None and
isinstance(obj, (ABCSeries, ABCDataFrame))):
if how is not None:
warnings.warn("The how kw argument is deprecated and removed "
"in a future version. You can resample prior "
"to passing to a window function", FutureWarning,
stacklevel=6)

obj = obj.resample(self.freq).aggregate(how or 'asfreq')

return obj, index

def _create_blocks(self, how):
Expand Down Expand Up @@ -374,14 +358,11 @@ class Window(_Window):
Minimum number of observations in window required to have a value
(otherwise result is NA). For a window that is specified by an offset,
this will default to 1.
freq : string or DateOffset object, optional (default None)
.. deprecated:: 0.18.0
Frequency to conform the data to before computing the statistic.
Specified as a frequency string or DateOffset object.
center : boolean, default False
Set the labels at the center of the window.
win_type : string, default None
Provide a window type. See the notes below.
Provide a window type. If ``None``, all points are evenly weighted.
See the notes below for further information.
on : string, optional
For a DataFrame, column on which to calculate
the rolling window, rather than the index
Expand Down Expand Up @@ -479,10 +460,6 @@ class Window(_Window):
By default, the result is set to the right edge of the window. This can be
changed to the center of the window by setting ``center=True``.

The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the offsets & frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.

Expand All @@ -506,6 +483,11 @@ class Window(_Window):
If ``win_type=None`` all points are evenly weighted. To learn more about
different window types see `scipy.signal window functions
<https://docs.scipy.org/doc/scipy/reference/signal.html#window-functions>`__.

See Also
--------
expanding : Provides expanding transformations.
ewm : Provides exponential weighted functions
"""

def validate(self):
Expand Down Expand Up @@ -876,8 +858,6 @@ def sum(self, *args, **kwargs):

def max(self, how=None, *args, **kwargs):
nv.validate_window_func('max', args, kwargs)
if self.freq is not None and how is None:
how = 'max'
return self._apply('roll_max', 'max', how=how, **kwargs)

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

def min(self, how=None, *args, **kwargs):
nv.validate_window_func('min', args, kwargs)
if self.freq is not None and how is None:
how = 'min'
return self._apply('roll_min', 'min', how=how, **kwargs)

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

def median(self, how=None, **kwargs):
if self.freq is not None and how is None:
how = 'median'
return self._apply('roll_median_c', 'median', how=how, **kwargs)

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

def _get_corr(a, b):
a = a.rolling(window=window, min_periods=self.min_periods,
freq=self.freq, center=self.center)
center=self.center)
b = b.rolling(window=window, min_periods=self.min_periods,
freq=self.freq, center=self.center)
center=self.center)

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

Expand Down Expand Up @@ -1136,7 +1112,7 @@ def _validate_monotonic(self):
"monotonic".format(formatted))

def _validate_freq(self):
""" validate & return our freq """
""" validate & return window frequency """
from pandas.tseries.frequencies import to_offset
try:
return to_offset(self.window)
Expand Down Expand Up @@ -1346,10 +1322,6 @@ class Expanding(_Rolling_and_Expanding):
min_periods : int, default None
Minimum number of observations in window required to have a value
(otherwise result is NA).
freq : string or DateOffset object, optional (default None)
.. deprecated:: 0.18.0
Frequency to conform the data to before computing the statistic.
Specified as a frequency string or DateOffset object.
center : boolean, default False
Set the labels at the center of the window.
axis : int or string, default 0
Expand Down Expand Up @@ -1382,17 +1354,18 @@ class Expanding(_Rolling_and_Expanding):
By default, the result is set to the right edge of the window. This can be
changed to the center of the window by setting ``center=True``.

The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).
See Also
--------
rolling : Provides rolling window calculations
ewm : Provides exponential weighted functions
"""

_attributes = ['min_periods', 'freq', 'center', 'axis']
_attributes = ['min_periods', 'center', 'axis']

def __init__(self, obj, min_periods=1, freq=None, center=False, axis=0,
def __init__(self, obj, min_periods=1, center=False, axis=0,
**kwargs):
super(Expanding, self).__init__(obj=obj, min_periods=min_periods,
freq=freq, center=center, axis=axis)
center=center, axis=axis)

@property
def _constructor(self):
Expand Down Expand Up @@ -1611,9 +1584,6 @@ class EWM(_Rolling):
min_periods : int, default 0
Minimum number of observations in window required to have a value
(otherwise result is NA).
freq : None or string alias / date offset object, default=None
.. deprecated:: 0.18.0
Frequency to conform to before computing statistic
adjust : boolean, default True
Divide by decaying adjustment factor in beginning periods to account
for imbalance in relative weightings (viewing EWMA as a moving average)
Expand Down Expand Up @@ -1651,10 +1621,6 @@ class EWM(_Rolling):
parameter descriptions above; see the link at the end of this section for
a detailed explanation.

The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

When adjust is True (default), weighted averages are calculated using
weights (1-alpha)**(n-1), (1-alpha)**(n-2), ..., 1-alpha, 1.

Expand All @@ -1674,16 +1640,20 @@ class EWM(_Rolling):

More details can be found at
http://pandas.pydata.org/pandas-docs/stable/computation.html#exponentially-weighted-windows

See Also
--------
rolling : Provides rolling window calculations
expanding : Provides expanding transformations.
"""
_attributes = ['com', 'min_periods', 'freq', 'adjust', 'ignore_na', 'axis']
_attributes = ['com', 'min_periods', 'adjust', 'ignore_na', 'axis']

def __init__(self, obj, com=None, span=None, halflife=None, alpha=None,
min_periods=0, freq=None, adjust=True, ignore_na=False,
min_periods=0, adjust=True, ignore_na=False,
axis=0):
self.obj = obj
self.com = _get_center_of_mass(com, span, halflife, alpha)
self.min_periods = min_periods
self.freq = freq
self.adjust = adjust
self.ignore_na = ignore_na
self.axis = axis
Expand Down
3 changes: 2 additions & 1 deletion pandas/stats/moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def ensure_compat(dispatch, name, arg, func_kw=None, *args, **kwargs):
if value is not None:
kwds[k] = value

# TODO: the below is only in place temporary until this module is removed.
kwargs.pop('freq', None) # freq removed in 0.22
# how is a keyword that if not-None should be in kwds
how = kwargs.pop('how', None)
if how is not None:
Expand Down Expand Up @@ -680,7 +682,6 @@ def f(arg, min_periods=1, freq=None, **kwargs):
name,
arg,
min_periods=min_periods,
freq=freq,
func_kw=func_kw,
**kwargs)
return f
Expand Down
Loading