Skip to content

Commit 2f4ba4e

Browse files
author
tp
committed
Remove how keyword from df.rolling() etc.
1 parent fdba133 commit 2f4ba4e

File tree

4 files changed

+30
-72
lines changed

4 files changed

+30
-72
lines changed

doc/source/computation.rst

-6
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,6 @@ accept the following arguments:
253253
result is NA)
254254
- ``center``: boolean, whether to set the labels at the center (default is False)
255255

256-
.. warning::
257-
258-
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.
259-
260-
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.
261-
262256
We can then call methods on these ``rolling`` objects. These return like-indexed objects:
263257

264258
.. ipython:: python

doc/source/whatsnew/v0.22.0.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ Removal of prior version deprecations/changes
237237
- The ``SparseList`` class has been removed (:issue:`14007`)
238238
- The ``pandas.io.wb`` and ``pandas.io.data`` stub modules have been removed (:issue:`13735`)
239239
- ``Categorical.from_array`` has been removed (:issue:`13854`)
240-
- The ``freq`` parameter has been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
241-
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601)
240+
- The ``freq`` and ``how`` parameters have been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
241+
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601 & :issue:18668)
242242
- ``DatetimeIndex.to_datetime``, ``Timestamp.to_datetime``, ``PeriodIndex.to_datetime``, and ``Index.to_datetime`` have been removed (:issue:`8254`, :issue:`14096`, :issue:`14113`)
243243

244244
.. _whatsnew_0220.performance:

pandas/core/window.py

+23-59
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ def validate(self):
106106
raise ValueError("closed must be 'right', 'left', 'both' or "
107107
"'neither'")
108108

109-
def _convert_freq(self, how=None):
109+
def _convert_freq(self):
110110
""" resample according to the how, return a new object """
111111

112112
obj = self._selected_obj
113113
index = None
114114
return obj, index
115115

116-
def _create_blocks(self, how):
116+
def _create_blocks(self):
117117
""" split data into blocks & return conformed data """
118118

119-
obj, index = self._convert_freq(how)
119+
obj, index = self._convert_freq()
120120
if index is not None:
121121
index = self._on
122122

@@ -196,7 +196,7 @@ def _get_index(self, index=None):
196196
return index, index.asi8
197197
return index, index
198198

199-
def _prep_values(self, values=None, kill_inf=True, how=None):
199+
def _prep_values(self, values=None, kill_inf=True):
200200

201201
if values is None:
202202
values = getattr(self._selected_obj, 'values', self._selected_obj)
@@ -320,22 +320,10 @@ def aggregate(self, arg, *args, **kwargs):
320320
agg = aggregate
321321

322322
_shared_docs['sum'] = dedent("""
323-
%(name)s sum
324-
325-
Parameters
326-
----------
327-
how : string, default None
328-
.. deprecated:: 0.18.0
329-
Method for down- or re-sampling""")
323+
%(name)s sum""")
330324

331325
_shared_docs['mean'] = dedent("""
332-
%(name)s mean
333-
334-
Parameters
335-
----------
336-
how : string, default None
337-
.. deprecated:: 0.18.0
338-
Method for down- or re-sampling""")
326+
%(name)s mean""")
339327

340328

341329
class Window(_Window):
@@ -549,17 +537,14 @@ def _pop_args(win_type, arg_names, kwargs):
549537
# GH #15662. `False` makes symmetric window, rather than periodic.
550538
return sig.get_window(win_type, window, False).astype(float)
551539

552-
def _apply_window(self, mean=True, how=None, **kwargs):
540+
def _apply_window(self, mean=True, **kwargs):
553541
"""
554542
Applies a moving window of type ``window_type`` on the data.
555543
556544
Parameters
557545
----------
558546
mean : boolean, default True
559547
If True computes weighted mean, else weighted sum
560-
how : string, default to None
561-
.. deprecated:: 0.18.0
562-
how to resample
563548
564549
Returns
565550
-------
@@ -569,7 +554,7 @@ def _apply_window(self, mean=True, how=None, **kwargs):
569554
window = self._prep_window(**kwargs)
570555
center = self.center
571556

572-
blocks, obj, index = self._create_blocks(how=how)
557+
blocks, obj, index = self._create_blocks()
573558
results = []
574559
for b in blocks:
575560
try:
@@ -686,7 +671,7 @@ def __init__(self, obj, *args, **kwargs):
686671
cov = GroupByMixin._dispatch('cov', other=None, pairwise=None)
687672

688673
def _apply(self, func, name, window=None, center=None,
689-
check_minp=None, how=None, **kwargs):
674+
check_minp=None, **kwargs):
690675
"""
691676
dispatch to apply; we are stripping all of the _apply kwargs and
692677
performing the original function call on the grouped object
@@ -710,7 +695,7 @@ def _constructor(self):
710695
return Rolling
711696

712697
def _apply(self, func, name=None, window=None, center=None,
713-
check_minp=None, how=None, **kwargs):
698+
check_minp=None, **kwargs):
714699
"""
715700
Rolling statistical measure using supplied function. Designed to be
716701
used with passed-in Cython array-based functions.
@@ -723,9 +708,6 @@ def _apply(self, func, name=None, window=None, center=None,
723708
window : int/array, default to _get_window()
724709
center : boolean, default to self.center
725710
check_minp : function, default to _use_window
726-
how : string, default to None
727-
.. deprecated:: 0.18.0
728-
how to resample
729711
730712
Returns
731713
-------
@@ -739,7 +721,7 @@ def _apply(self, func, name=None, window=None, center=None,
739721
if check_minp is None:
740722
check_minp = _use_window
741723

742-
blocks, obj, index = self._create_blocks(how=how)
724+
blocks, obj, index = self._create_blocks()
743725
index, indexi = self._get_index(index=index)
744726
results = []
745727
for b in blocks:
@@ -803,7 +785,7 @@ class _Rolling_and_Expanding(_Rolling):
803785

804786
def count(self):
805787

806-
blocks, obj, index = self._create_blocks(how=None)
788+
blocks, obj, index = self._create_blocks()
807789
index, indexi = self._get_index(index=index)
808790

809791
window = self._get_window()
@@ -849,45 +831,30 @@ def sum(self, *args, **kwargs):
849831

850832
_shared_docs['max'] = dedent("""
851833
%(name)s maximum
834+
""")
852835

853-
Parameters
854-
----------
855-
how : string, default 'max'
856-
.. deprecated:: 0.18.0
857-
Method for down- or re-sampling""")
858-
859-
def max(self, how=None, *args, **kwargs):
836+
def max(self, *args, **kwargs):
860837
nv.validate_window_func('max', args, kwargs)
861-
return self._apply('roll_max', 'max', how=how, **kwargs)
838+
return self._apply('roll_max', 'max', **kwargs)
862839

863840
_shared_docs['min'] = dedent("""
864841
%(name)s minimum
842+
""")
865843

866-
Parameters
867-
----------
868-
how : string, default 'min'
869-
.. deprecated:: 0.18.0
870-
Method for down- or re-sampling""")
871-
872-
def min(self, how=None, *args, **kwargs):
844+
def min(self, *args, **kwargs):
873845
nv.validate_window_func('min', args, kwargs)
874-
return self._apply('roll_min', 'min', how=how, **kwargs)
846+
return self._apply('roll_min', 'min', **kwargs)
875847

876848
def mean(self, *args, **kwargs):
877849
nv.validate_window_func('mean', args, kwargs)
878850
return self._apply('roll_mean', 'mean', **kwargs)
879851

880852
_shared_docs['median'] = dedent("""
881853
%(name)s median
854+
""")
882855

883-
Parameters
884-
----------
885-
how : string, default 'median'
886-
.. deprecated:: 0.18.0
887-
Method for down- or re-sampling""")
888-
889-
def median(self, how=None, **kwargs):
890-
return self._apply('roll_median_c', 'median', how=how, **kwargs)
856+
def median(self, **kwargs):
857+
return self._apply('roll_median_c', 'median', **kwargs)
891858

892859
_shared_docs['std'] = dedent("""
893860
%(name)s standard deviation
@@ -1709,23 +1676,20 @@ def aggregate(self, arg, *args, **kwargs):
17091676

17101677
agg = aggregate
17111678

1712-
def _apply(self, func, how=None, **kwargs):
1679+
def _apply(self, func, **kwargs):
17131680
"""Rolling statistical measure using supplied function. Designed to be
17141681
used with passed-in Cython array-based functions.
17151682
17161683
Parameters
17171684
----------
17181685
func : string/callable to apply
1719-
how : string, default to None
1720-
.. deprecated:: 0.18.0
1721-
how to resample
17221686
17231687
Returns
17241688
-------
17251689
y : type of input argument
17261690
17271691
"""
1728-
blocks, obj, index = self._create_blocks(how=how)
1692+
blocks, obj, index = self._create_blocks()
17291693
results = []
17301694
for b in blocks:
17311695
try:

pandas/tests/test_window.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ def test_rolling_max_gh6297(self):
30193019
x = series.resample('D').max().rolling(window=1).max()
30203020
tm.assert_series_equal(expected, x)
30213021

3022-
def test_rolling_max_how_resample(self):
3022+
def test_rolling_max_resample(self):
30233023

30243024
indices = [datetime(1975, 1, i) for i in range(1, 6)]
30253025
# 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):
30403040
# Now specify median (10.0)
30413041
expected = Series([0.0, 1.0, 2.0, 3.0, 10.0],
30423042
index=[datetime(1975, 1, i, 0) for i in range(1, 6)])
3043-
x = series.resample('D').median().rolling(window=1).max(how='median')
3043+
x = series.resample('D').median().rolling(window=1).max()
30443044
tm.assert_series_equal(expected, x)
30453045

30463046
# Now specify mean (4+10+20)/3
30473047
v = (4.0 + 10.0 + 20.0) / 3.0
30483048
expected = Series([0.0, 1.0, 2.0, 3.0, v],
30493049
index=[datetime(1975, 1, i, 0) for i in range(1, 6)])
3050-
x = series.resample('D').mean().rolling(window=1).max(how='mean')
3050+
x = series.resample('D').mean().rolling(window=1).max()
30513051
tm.assert_series_equal(expected, x)
30523052

3053-
def test_rolling_min_how_resample(self):
3053+
def test_rolling_min_resample(self):
30543054

30553055
indices = [datetime(1975, 1, i) for i in range(1, 6)]
30563056
# 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):
30683068
r = series.resample('D').min().rolling(window=1)
30693069
tm.assert_series_equal(expected, r.min())
30703070

3071-
def test_rolling_median_how_resample(self):
3071+
def test_rolling_median_resample(self):
30723072

30733073
indices = [datetime(1975, 1, i) for i in range(1, 6)]
30743074
# So that we can have 3 datapoints on last day (4, 10, and 20)

0 commit comments

Comments
 (0)