Skip to content

Commit 3156395

Browse files
committed
DEPR: deprecate pd.rolling_*, pd.expanding_*, pd.ewm*
1 parent e47bd99 commit 3156395

File tree

10 files changed

+732
-650
lines changed

10 files changed

+732
-650
lines changed

doc/source/api.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,9 +1505,9 @@ Window
15051505
------
15061506
.. currentmodule:: pandas.core.window
15071507

1508-
Rolling objects are returned by rolling calls: :func:`pandas.DataFrame.rolling`, :func:`pandas.Series.rolling`, etc.
1509-
Expanding objects are returned by rolling calls: :func:`pandas.DataFrame.expanding`, :func:`pandas.Series.expanding`, etc.
1510-
EWM objects are returned by rolling calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.
1508+
Rolling objects are returned by ``.rolling`` calls: :func:`pandas.DataFrame.rolling`, :func:`pandas.Series.rolling`, etc.
1509+
Expanding objects are returned by ``.expanding`` calls: :func:`pandas.DataFrame.expanding`, :func:`pandas.Series.expanding`, etc.
1510+
EWM objects are returned by ``.ewm`` calls: :func:`pandas.DataFrame.ewm`, :func:`pandas.Series.ewm`, etc.
15111511

15121512
Standard moving window functions
15131513
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1526,13 +1526,13 @@ Standard moving window functions
15261526
Rolling.min
15271527
Rolling.max
15281528
Rolling.corr
1529-
Rolling.corr_pairwise
15301529
Rolling.cov
15311530
Rolling.skew
15321531
Rolling.kurt
15331532
Rolling.apply
15341533
Rolling.quantile
1535-
Rolling.window
1534+
Window.mean
1535+
Window.sum
15361536

15371537
.. _api.functions_expanding:
15381538

@@ -1553,7 +1553,6 @@ Standard expanding window functions
15531553
Expanding.min
15541554
Expanding.max
15551555
Expanding.corr
1556-
Expanding.corr_pairwise
15571556
Expanding.cov
15581557
Expanding.skew
15591558
Expanding.kurt

doc/source/computation.rst

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,12 @@ Window Functions
203203

204204
.. warning::
205205

206-
Prior to version 0.18.0, these were module level functions that have been deprecated.
207-
You can see the previous documentation
206+
Prior to version 0.18.0, ``pd.rolling_*``, ``pd.expanding_*``, and ``pd.ewm*`` were module level
207+
functions and are now deprecated and replaced by the corresponding method call.
208+
209+
The deprecation warning will show the new syntax, see an example :ref:`here <whatsnew_0180.window_deprecations>`
210+
211+
You can view the previous documentation
208212
`here <http://pandas.pydata.org/pandas-docs/version/0.17.1/computation.html#moving-rolling-statistics-moments>`__
209213

210214
For working with data, a number of windows functions are provided for
@@ -242,10 +246,6 @@ accept the following arguments:
242246
result is NA)
243247
- ``freq``: optionally specify a :ref:`frequency string <timeseries.alias>`
244248
or :ref:`DateOffset <timeseries.offsets>` to pre-conform the data to.
245-
- ``how``: optionally specify method for down or re-sampling. Default is
246-
is ``min`` for :meth:`~Rolling.min`, ``max`` for :meth:`~Rolling.max`, ``median`` for
247-
:meth:`~Rolling.median`, and ``mean`` for all other rolling functions. See
248-
:meth:`DataFrame.resample`'s how argument for more information.
249249

250250
We can then call functions on these ``rolling`` objects. Which return like-indexed objects:
251251

@@ -323,7 +323,7 @@ compute the mean absolute deviation on a rolling basis:
323323
Rolling Windows
324324
~~~~~~~~~~~~~~~
325325

326-
The :meth:`~Window.mean`, and :meth:`~Window.sum` functions performs a generic rolling window computation
326+
The :meth:`~Window.mean`, and :meth:`~Window.sum` functions perform a generic rolling window computation
327327
on the input data. The weights used in the window are specified by the ``win_type``
328328
keyword. The list of recognized types are:
329329

@@ -361,6 +361,9 @@ For some windowing functions, additional parameters must be specified:
361361
362362
ser.rolling(window=5, win_type='gaussian').mean(std=0.1)
363363
364+
Centering Windows
365+
~~~~~~~~~~~~~~~~~
366+
364367
By default the labels are set to the right edge of the window, but a
365368
``center`` keyword is available so the labels can be set at the center.
366369
This keyword is available in other rolling functions as well.

doc/source/conf.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,7 @@
224224
'pandas.io.pickle.read_pickle', 'pandas.io.pytables.HDFStore.append', 'pandas.io.pytables.HDFStore.get',
225225
'pandas.io.pytables.HDFStore.put', 'pandas.io.pytables.HDFStore.select', 'pandas.io.pytables.read_hdf',
226226
'pandas.io.sql.read_sql', 'pandas.io.sql.read_frame', 'pandas.io.sql.write_frame',
227-
'pandas.io.stata.read_stata', 'pandas.stats.moments.ewma', 'pandas.stats.moments.ewmcorr',
228-
'pandas.stats.moments.ewmcov', 'pandas.stats.moments.ewmstd', 'pandas.stats.moments.ewmvar',
229-
'pandas.stats.moments.expanding_apply', 'pandas.stats.moments.expanding_corr', 'pandas.stats.moments.expanding_count',
230-
'pandas.stats.moments.expanding_cov', 'pandas.stats.moments.expanding_kurt', 'pandas.stats.moments.expanding_mean',
231-
'pandas.stats.moments.expanding_median', 'pandas.stats.moments.expanding_quantile', 'pandas.stats.moments.expanding_skew',
232-
'pandas.stats.moments.expanding_std', 'pandas.stats.moments.expanding_sum', 'pandas.stats.moments.expanding_var',
233-
'pandas.stats.moments.rolling_apply', 'pandas.stats.moments.rolling_corr', 'pandas.stats.moments.rolling_count',
234-
'pandas.stats.moments.rolling_cov', 'pandas.stats.moments.rolling_kurt', 'pandas.stats.moments.rolling_mean',
235-
'pandas.stats.moments.rolling_median', 'pandas.stats.moments.rolling_quantile', 'pandas.stats.moments.rolling_skew',
236-
'pandas.stats.moments.rolling_std', 'pandas.stats.moments.rolling_sum', 'pandas.stats.moments.rolling_var']
227+
'pandas.io.stata.read_stata']
237228

238229
html_additional_pages = {'generated/' + page: 'api_redirect.html' for page in moved_api_pages}
239230

doc/source/cookbook.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to
517517
def Red(x):
518518
return functools.reduce(CumRet,x,1.0)
519519
520-
pd.expanding_apply(S, Red)
520+
S.expanding().apply(Red)
521521
522522
523523
`Replacing some values with mean of the rest of a group
@@ -639,7 +639,7 @@ Create a list of dataframes, split using a delineation based on logic included i
639639
df = pd.DataFrame(data={'Case' : ['A','A','A','B','A','A','B','A','A'],
640640
'Data' : np.random.randn(9)})
641641
642-
dfs = list(zip(*df.groupby(pd.rolling_median((1*(df['Case']=='B')).cumsum(),3,True))))[-1]
642+
dfs = list(zip(*df.groupby((1*(df['Case']=='B')).cumsum().rolling(window=3,min_periods=1).median())))[-1]
643643
644644
dfs[0]
645645
dfs[1]

doc/source/groupby.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ to standardize the data within each group:
519519
520520
index = pd.date_range('10/1/1999', periods=1100)
521521
ts = pd.Series(np.random.normal(0.5, 2, 1100), index)
522-
ts = pd.rolling_mean(ts, 100, 100).dropna()
522+
ts = ts.rolling(window=100,min_periods=100).mean().dropna()
523523
524524
ts.head()
525525
ts.tail()

doc/source/whatsnew/v0.18.0.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,40 @@ Other API Changes
210210
Deprecations
211211
^^^^^^^^^^^^
212212

213+
.. _whatsnew_0180.window_deprecations:
213214

215+
- Function ``pd.rolling_*``, ``pd.expanding_*``, and ``pd.ewm*`` are deprecated and replaced by the corresponding method call. Note that
216+
the new suggested syntax includes all of the arguments (even if default) (:issue:`11603`)
214217

218+
.. code-block:: python
215219

220+
In [1]: s = Series(range(3))
216221

222+
In [2]: pd.rolling_mean(s,window=2,min_periods=1)
223+
FutureWarning: pd.rolling_mean is deprecated for Series and will be removed in a future version, replace with
224+
Series.rolling(min_periods=1,window=2,center=False).mean()
225+
Out[2]:
226+
0 0.0
227+
1 0.5
228+
2 1.5
229+
dtype: float64
230+
231+
In [3]: pd.rolling_cov(s, s, window=2)
232+
FutureWarning: pd.rolling_cov is deprecated for Series and will be removed in a future version, replace with
233+
Series.rolling(window=2).cov(other=<Series>)
234+
Out[3]:
235+
0 NaN
236+
1 0.5
237+
2 0.5
238+
dtype: float64
217239

218240
.. _whatsnew_0180.prior_deprecations:
219241

220242
Removal of prior version deprecations/changes
221243
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
222244

223-
Removal of ``rolling_corr_parwise`` in favor of ``.rolling().corr(pairwise=True)`` (:issue:`4950`)
224-
Removal of ``expanding_corr_parwise`` in favor of ``.expanding().corr(pairwise=True)`` (:issue:`4950`)
245+
- Removal of ``rolling_corr_parwise`` in favor of ``.rolling().corr(pairwise=True)`` (:issue:`4950`)
246+
- Removal of ``expanding_corr_parwise`` in favor of ``.expanding().corr(pairwise=True)`` (:issue:`4950`)
225247

226248

227249

pandas/core/generic.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4741,26 +4741,25 @@ def _add_series_or_dataframe_operations(cls):
47414741

47424742
@Appender(rwindow.rolling.__doc__)
47434743
def rolling(self, window, min_periods=None, freq=None, center=False,
4744-
how=None, win_type=None, axis=0):
4744+
win_type=None, axis=0):
47454745
axis = self._get_axis_number(axis)
47464746
return rwindow.rolling(self, window=window, min_periods=min_periods, freq=freq, center=center,
4747-
how=how, win_type=win_type, axis=axis)
4747+
win_type=win_type, axis=axis)
47484748
cls.rolling = rolling
47494749

47504750
@Appender(rwindow.expanding.__doc__)
4751-
def expanding(self, min_periods=None, freq=None, center=False,
4752-
how=None, axis=0):
4751+
def expanding(self, min_periods=1, freq=None, center=False, axis=0):
47534752
axis = self._get_axis_number(axis)
47544753
return rwindow.expanding(self, min_periods=min_periods, freq=freq, center=center,
4755-
how=how, axis=axis)
4754+
axis=axis)
47564755
cls.expanding = expanding
47574756

47584757
@Appender(rwindow.ewm.__doc__)
47594758
def ewm(self, com=None, span=None, halflife=None, min_periods=0, freq=None,
4760-
adjust=True, how=None, ignore_na=False, axis=0):
4759+
adjust=True, ignore_na=False, axis=0):
47614760
axis = self._get_axis_number(axis)
47624761
return rwindow.ewm(self, com=com, span=span, halflife=halflife, min_periods=min_periods,
4763-
freq=freq, adjust=adjust, how=how, ignore_na=ignore_na, axis=axis)
4762+
freq=freq, adjust=adjust, ignore_na=ignore_na, axis=axis)
47644763
cls.ewm = ewm
47654764

47664765
def _doc_parms(cls):

0 commit comments

Comments
 (0)