diff --git a/doc/source/computation.rst b/doc/source/computation.rst index 66e16808f6af9..49ac516af6d37 100644 --- a/doc/source/computation.rst +++ b/doc/source/computation.rst @@ -253,12 +253,6 @@ accept the following arguments: result is NA) - ``center``: boolean, whether to set the labels at the center (default is False) -.. warning:: - - The ``freq`` and ``how`` arguments were in the API prior to 0.18.0 changes. These are deprecated in the new API. You can simply resample the input prior to creating a window function. - - For example, instead of ``s.rolling(window=5,freq='D').max()`` to get the max value on a rolling 5 Day window, one could use ``s.resample('D').max().rolling(window=5).max()``, which first resamples the data to daily data, then provides a rolling 5 day window. - We can then call methods on these ``rolling`` objects. These return like-indexed objects: .. ipython:: python diff --git a/doc/source/whatsnew/v0.22.0.txt b/doc/source/whatsnew/v0.22.0.txt index d34c1f3535509..5b23f20b5651d 100644 --- a/doc/source/whatsnew/v0.22.0.txt +++ b/doc/source/whatsnew/v0.22.0.txt @@ -237,8 +237,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) +- The ``freq`` and ``how`` parameters have been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame + and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601 & :issue:18668) - ``DatetimeIndex.to_datetime``, ``Timestamp.to_datetime``, ``PeriodIndex.to_datetime``, and ``Index.to_datetime`` have been removed (:issue:`8254`, :issue:`14096`, :issue:`14113`) .. _whatsnew_0220.performance: diff --git a/pandas/core/window.py b/pandas/core/window.py index 807f8bfa12674..5ad8d20cc03e2 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -106,17 +106,17 @@ def validate(self): raise ValueError("closed must be 'right', 'left', 'both' or " "'neither'") - def _convert_freq(self, how=None): + def _convert_freq(self): """ resample according to the how, return a new object """ obj = self._selected_obj index = None return obj, index - def _create_blocks(self, how): + def _create_blocks(self): """ split data into blocks & return conformed data """ - obj, index = self._convert_freq(how) + obj, index = self._convert_freq() if index is not None: index = self._on @@ -196,7 +196,7 @@ def _get_index(self, index=None): return index, index.asi8 return index, index - def _prep_values(self, values=None, kill_inf=True, how=None): + def _prep_values(self, values=None, kill_inf=True): if values is None: values = getattr(self._selected_obj, 'values', self._selected_obj) @@ -320,22 +320,10 @@ def aggregate(self, arg, *args, **kwargs): agg = aggregate _shared_docs['sum'] = dedent(""" - %(name)s sum - - Parameters - ---------- - how : string, default None - .. deprecated:: 0.18.0 - Method for down- or re-sampling""") + %(name)s sum""") _shared_docs['mean'] = dedent(""" - %(name)s mean - - Parameters - ---------- - how : string, default None - .. deprecated:: 0.18.0 - Method for down- or re-sampling""") + %(name)s mean""") class Window(_Window): @@ -549,7 +537,7 @@ def _pop_args(win_type, arg_names, kwargs): # GH #15662. `False` makes symmetric window, rather than periodic. return sig.get_window(win_type, window, False).astype(float) - def _apply_window(self, mean=True, how=None, **kwargs): + def _apply_window(self, mean=True, **kwargs): """ Applies a moving window of type ``window_type`` on the data. @@ -557,9 +545,6 @@ def _apply_window(self, mean=True, how=None, **kwargs): ---------- mean : boolean, default True If True computes weighted mean, else weighted sum - how : string, default to None - .. deprecated:: 0.18.0 - how to resample Returns ------- @@ -569,7 +554,7 @@ def _apply_window(self, mean=True, how=None, **kwargs): window = self._prep_window(**kwargs) center = self.center - blocks, obj, index = self._create_blocks(how=how) + blocks, obj, index = self._create_blocks() results = [] for b in blocks: try: @@ -686,7 +671,7 @@ def __init__(self, obj, *args, **kwargs): cov = GroupByMixin._dispatch('cov', other=None, pairwise=None) def _apply(self, func, name, window=None, center=None, - check_minp=None, how=None, **kwargs): + check_minp=None, **kwargs): """ dispatch to apply; we are stripping all of the _apply kwargs and performing the original function call on the grouped object @@ -710,7 +695,7 @@ def _constructor(self): return Rolling def _apply(self, func, name=None, window=None, center=None, - check_minp=None, how=None, **kwargs): + check_minp=None, **kwargs): """ Rolling statistical measure using supplied function. Designed to be used with passed-in Cython array-based functions. @@ -723,9 +708,6 @@ def _apply(self, func, name=None, window=None, center=None, window : int/array, default to _get_window() center : boolean, default to self.center check_minp : function, default to _use_window - how : string, default to None - .. deprecated:: 0.18.0 - how to resample Returns ------- @@ -739,7 +721,7 @@ def _apply(self, func, name=None, window=None, center=None, if check_minp is None: check_minp = _use_window - blocks, obj, index = self._create_blocks(how=how) + blocks, obj, index = self._create_blocks() index, indexi = self._get_index(index=index) results = [] for b in blocks: @@ -803,7 +785,7 @@ class _Rolling_and_Expanding(_Rolling): def count(self): - blocks, obj, index = self._create_blocks(how=None) + blocks, obj, index = self._create_blocks() index, indexi = self._get_index(index=index) window = self._get_window() @@ -849,29 +831,19 @@ def sum(self, *args, **kwargs): _shared_docs['max'] = dedent(""" %(name)s maximum + """) - Parameters - ---------- - how : string, default 'max' - .. deprecated:: 0.18.0 - Method for down- or re-sampling""") - - def max(self, how=None, *args, **kwargs): + def max(self, *args, **kwargs): nv.validate_window_func('max', args, kwargs) - return self._apply('roll_max', 'max', how=how, **kwargs) + return self._apply('roll_max', 'max', **kwargs) _shared_docs['min'] = dedent(""" %(name)s minimum + """) - Parameters - ---------- - how : string, default 'min' - .. deprecated:: 0.18.0 - Method for down- or re-sampling""") - - def min(self, how=None, *args, **kwargs): + def min(self, *args, **kwargs): nv.validate_window_func('min', args, kwargs) - return self._apply('roll_min', 'min', how=how, **kwargs) + return self._apply('roll_min', 'min', **kwargs) def mean(self, *args, **kwargs): nv.validate_window_func('mean', args, kwargs) @@ -879,15 +851,10 @@ def mean(self, *args, **kwargs): _shared_docs['median'] = dedent(""" %(name)s median + """) - Parameters - ---------- - how : string, default 'median' - .. deprecated:: 0.18.0 - Method for down- or re-sampling""") - - def median(self, how=None, **kwargs): - return self._apply('roll_median_c', 'median', how=how, **kwargs) + def median(self, **kwargs): + return self._apply('roll_median_c', 'median', **kwargs) _shared_docs['std'] = dedent(""" %(name)s standard deviation @@ -1709,23 +1676,20 @@ def aggregate(self, arg, *args, **kwargs): agg = aggregate - def _apply(self, func, how=None, **kwargs): + def _apply(self, func, **kwargs): """Rolling statistical measure using supplied function. Designed to be used with passed-in Cython array-based functions. Parameters ---------- func : string/callable to apply - how : string, default to None - .. deprecated:: 0.18.0 - how to resample Returns ------- y : type of input argument """ - blocks, obj, index = self._create_blocks(how=how) + blocks, obj, index = self._create_blocks() results = [] for b in blocks: try: diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index db94cd08b0050..661c7dfcc50fc 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -3019,7 +3019,7 @@ def test_rolling_max_gh6297(self): x = series.resample('D').max().rolling(window=1).max() tm.assert_series_equal(expected, x) - def test_rolling_max_how_resample(self): + def test_rolling_max_resample(self): indices = [datetime(1975, 1, i) for i in range(1, 6)] # So that we can have 3 datapoints on last day (4, 10, and 20) @@ -3040,17 +3040,17 @@ def test_rolling_max_how_resample(self): # Now specify median (10.0) expected = Series([0.0, 1.0, 2.0, 3.0, 10.0], index=[datetime(1975, 1, i, 0) for i in range(1, 6)]) - x = series.resample('D').median().rolling(window=1).max(how='median') + x = series.resample('D').median().rolling(window=1).max() tm.assert_series_equal(expected, x) # Now specify mean (4+10+20)/3 v = (4.0 + 10.0 + 20.0) / 3.0 expected = Series([0.0, 1.0, 2.0, 3.0, v], index=[datetime(1975, 1, i, 0) for i in range(1, 6)]) - x = series.resample('D').mean().rolling(window=1).max(how='mean') + x = series.resample('D').mean().rolling(window=1).max() tm.assert_series_equal(expected, x) - def test_rolling_min_how_resample(self): + def test_rolling_min_resample(self): indices = [datetime(1975, 1, i) for i in range(1, 6)] # So that we can have 3 datapoints on last day (4, 10, and 20) @@ -3068,7 +3068,7 @@ def test_rolling_min_how_resample(self): r = series.resample('D').min().rolling(window=1) tm.assert_series_equal(expected, r.min()) - def test_rolling_median_how_resample(self): + def test_rolling_median_resample(self): indices = [datetime(1975, 1, i) for i in range(1, 6)] # So that we can have 3 datapoints on last day (4, 10, and 20)