Skip to content

Commit 1890a88

Browse files
committed
cleanup based on comments
1 parent 05eb20f commit 1890a88

File tree

8 files changed

+355
-235
lines changed

8 files changed

+355
-235
lines changed

doc/source/computation.rst

+17-18
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ accept the following arguments:
243243
- ``window``: size of moving window
244244
- ``min_periods``: threshold of non-null data points to require (otherwise
245245
result is NA)
246+
- ``center``: boolean, whether to set the labels at the center (default is False)
246247

247248
.. warning::
248249

@@ -334,7 +335,7 @@ The following methods are available:
334335
:meth:`~Window.sum`, Sum of values
335336
:meth:`~Window.mean`, Mean of values
336337

337-
The weights used in the window are specified by the ``win_type``keyword. The list of recognized types are:
338+
The weights used in the window are specified by the ``win_type`` keyword. The list of recognized types are:
338339

339340
- ``boxcar``
340341
- ``triang``
@@ -370,27 +371,12 @@ For some windowing functions, additional parameters must be specified:
370371
371372
ser.rolling(window=5, win_type='gaussian').mean(std=0.1)
372373
373-
Centering Windows
374-
~~~~~~~~~~~~~~~~~
375-
376-
By default the labels are set to the right edge of the window, but a
377-
``center`` keyword is available so the labels can be set at the center.
378-
This keyword is available in other rolling functions as well.
379-
380-
.. ipython:: python
381-
382-
ser.rolling(window=5, win_type='boxcar').mean()
383-
384-
ser.rolling(window=5, win_type='boxcar', center=True).mean()
385-
386-
ser.rolling(window=5, center=True).mean()
387-
388374
.. _stats.moments.normalization:
389375

390376
.. note::
391377

392378
For ``.sum()`` with a ``win_type``, there is no normalization done to the
393-
weights. Passing custom weights of ``[1, 1, 1]`` will yield a different
379+
weights for the window. Passing custom weights of ``[1, 1, 1]`` will yield a different
394380
result than passing weights of ``[2, 2, 2]``, for example. When passing a
395381
``win_type`` instead of explicitly specifying the weights, the weights are
396382
already normalized so that the largest weight is 1.
@@ -399,6 +385,18 @@ This keyword is available in other rolling functions as well.
399385
such that the weights are normalized with respect to each other. Weights
400386
of ``[1, 1, 1]`` and ``[2, 2, 2]`` yield the same result.
401387

388+
Centering Windows
389+
~~~~~~~~~~~~~~~~~
390+
391+
By default the labels are set to the right edge of the window, but a
392+
``center`` keyword is available so the labels can be set at the center.
393+
This keyword is available in other rolling functions as well.
394+
395+
.. ipython:: python
396+
397+
ser.rolling(window=5).mean()
398+
ser.rolling(window=5, center=True).mean()
399+
402400
.. _stats.moments.binary:
403401

404402
Binary Window Functions
@@ -550,7 +548,7 @@ Furthermore you can pass a nested dict to indicate different aggregations on dif
550548

551549
.. ipython:: python
552550
553-
r.agg({'A' : {'ra' : 'sum'}, 'B' : {'rb' : 'std' }})
551+
r.agg({'A' : ['sum','std'], 'B' : ['mean','std'] })
554552
555553
556554
.. _stats.moments.expanding:
@@ -607,6 +605,7 @@ all accept are:
607605
- ``min_periods``: threshold of non-null data points to require. Defaults to
608606
minimum needed to compute statistic. No ``NaNs`` will be output once
609607
``min_periods`` non-null data points have been seen.
608+
- ``center``: boolean, whether to set the labels at the center (default is False)
610609

611610
.. note::
612611

doc/source/whatsnew/v0.14.0.txt

+11-4
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,18 @@ API changes
170170
:ref:`Computing rolling pairwise covariances and correlations
171171
<stats.moments.corr_pairwise>` in the docs.
172172

173-
.. ipython:: python
173+
.. code-block:: python
174+
175+
In [1]: df = DataFrame(np.random.randn(10,4),columns=list('ABCD'))
176+
177+
In [4]: covs = pd.rolling_cov(df[['A','B','C']], df[['B','C','D']], 5, pairwise=True)
174178

175-
df = DataFrame(np.random.randn(10,4),columns=list('ABCD'))
176-
covs = rolling_cov(df[['A','B','C']], df[['B','C','D']], 5, pairwise=True)
177-
covs[df.index[-1]]
179+
In [5]: covs[df.index[-1]]
180+
Out[5]:
181+
B C D
182+
A 0.035310 0.326593 -0.505430
183+
B 0.137748 -0.006888 -0.005383
184+
C -0.006888 0.861040 0.020762
178185

179186
- ``Series.iteritems()`` is now lazy (returns an iterator rather than a list). This was the documented behavior prior to 0.14. (:issue:`6760`)
180187

doc/source/whatsnew/v0.15.0.txt

+80-23
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ For full docs, see the :ref:`categorical introduction <categorical>` and the
6868

6969
.. ipython:: python
7070
:okwarning:
71-
71+
7272
df = DataFrame({"id":[1,2,3,4,5,6], "raw_grade":['a', 'b', 'b', 'a', 'a', 'e']})
7373

7474
df["grade"] = df["raw_grade"].astype("category")
@@ -353,9 +353,15 @@ Rolling/Expanding Moments improvements
353353

354354
New behavior
355355

356-
.. ipython:: python
356+
.. code-block:: python
357357

358-
rolling_min(s, window=10, min_periods=5)
358+
In [4]: pd.rolling_min(s, window=10, min_periods=5)
359+
Out[4]:
360+
0 NaN
361+
1 NaN
362+
2 NaN
363+
3 NaN
364+
dtype: float64
359365

360366
- :func:`rolling_max`, :func:`rolling_min`, :func:`rolling_sum`, :func:`rolling_mean`, :func:`rolling_median`,
361367
:func:`rolling_std`, :func:`rolling_var`, :func:`rolling_skew`, :func:`rolling_kurt`, :func:`rolling_quantile`,
@@ -381,9 +387,15 @@ Rolling/Expanding Moments improvements
381387

382388
New behavior (note final value is ``5 = sum([2, 3, NaN])``):
383389

384-
.. ipython:: python
390+
.. code-block:: python
385391

386-
rolling_sum(Series(range(4)), window=3, min_periods=0, center=True)
392+
In [7]: rolling_sum(Series(range(4)), window=3, min_periods=0, center=True)
393+
Out[7]:
394+
0 1
395+
1 3
396+
2 6
397+
3 5
398+
dtype: float64
387399

388400
- :func:`rolling_window` now normalizes the weights properly in rolling mean mode (`mean=True`) so that
389401
the calculated weighted means (e.g. 'triang', 'gaussian') are distributed about the same means as those
@@ -397,20 +409,27 @@ Rolling/Expanding Moments improvements
397409

398410
.. code-block:: python
399411

400-
In [39]: rolling_window(s, window=3, win_type='triang', center=True)
401-
Out[39]:
402-
0 NaN
403-
1 6.583333
404-
2 6.883333
405-
3 6.683333
406-
4 NaN
407-
dtype: float64
412+
In [39]: rolling_window(s, window=3, win_type='triang', center=True)
413+
Out[39]:
414+
0 NaN
415+
1 6.583333
416+
2 6.883333
417+
3 6.683333
418+
4 NaN
419+
dtype: float64
408420

409421
New behavior
410422

411423
.. ipython:: python
412424

413-
rolling_window(s, window=3, win_type='triang', center=True)
425+
In [10]: pd.rolling_window(s, window=3, win_type='triang', center=True)
426+
Out[10]:
427+
0 NaN
428+
1 9.875
429+
2 10.325
430+
3 10.025
431+
4 NaN
432+
dtype: float64
414433

415434
- Removed ``center`` argument from all :func:`expanding_ <expanding_apply>` functions (see :ref:`list <api.functions_expanding>`),
416435
as the results produced when ``center=True`` did not make much sense. (:issue:`7925`)
@@ -449,9 +468,17 @@ Rolling/Expanding Moments improvements
449468

450469
New behavior (note values start at index ``4``, the location of the 2nd (since ``min_periods=2``) non-empty value):
451470

452-
.. ipython:: python
471+
.. code-block:: python
453472

454-
ewma(s, com=3., min_periods=2)
473+
In [2]: pd.ewma(s, com=3., min_periods=2)
474+
Out[2]:
475+
0 NaN
476+
1 NaN
477+
2 NaN
478+
3 NaN
479+
4 1.759644
480+
5 2.383784
481+
dtype: float64
455482

456483
- :func:`ewmstd`, :func:`ewmvol`, :func:`ewmvar`, :func:`ewmcov`, and :func:`ewmcorr`
457484
now have an optional ``adjust`` argument, just like :func:`ewma` does,
@@ -465,11 +492,28 @@ Rolling/Expanding Moments improvements
465492
When ``ignore_na=True`` (which reproduces the pre-0.15.0 behavior), missing values are ignored in the weights calculation.
466493
(:issue:`7543`)
467494

468-
.. ipython:: python
495+
.. code-block:: python
496+
497+
In [7]: pd.ewma(Series([None, 1., 8.]), com=2.)
498+
Out[7]:
499+
0 NaN
500+
1 1.0
501+
2 5.2
502+
dtype: float64
503+
504+
In [8]: pd.ewma(Series([1., None, 8.]), com=2., ignore_na=True) # pre-0.15.0 behavior
505+
Out[8]:
506+
0 1.0
507+
1 1.0
508+
2 5.2
509+
dtype: float64
469510

470-
ewma(Series([None, 1., 8.]), com=2.)
471-
ewma(Series([1., None, 8.]), com=2., ignore_na=True) # pre-0.15.0 behavior
472-
ewma(Series([1., None, 8.]), com=2., ignore_na=False) # new default
511+
In [9]: pd.ewma(Series([1., None, 8.]), com=2., ignore_na=False) # new default
512+
Out[9]:
513+
0 1.000000
514+
1 1.000000
515+
2 5.846154
516+
dtype: float64
473517

474518
.. warning::
475519

@@ -525,10 +569,23 @@ Rolling/Expanding Moments improvements
525569
By comparison, the following 0.15.0 results have a ``NaN`` for entry ``0``,
526570
and the debiasing factors are decreasing (towards 1.25):
527571

528-
.. ipython:: python
572+
.. code-block:: python
529573

530-
ewmvar(s, com=2., bias=False)
531-
ewmvar(s, com=2., bias=False) / ewmvar(s, com=2., bias=True)
574+
In [14]: pd.ewmvar(s, com=2., bias=False)
575+
Out[14]:
576+
0 NaN
577+
1 0.500000
578+
2 1.210526
579+
3 4.089069
580+
dtype: float64
581+
582+
In [15]: pd.ewmvar(s, com=2., bias=False) / pd.ewmvar(s, com=2., bias=True)
583+
Out[15]:
584+
0 NaN
585+
1 2.083333
586+
2 1.583333
587+
3 1.425439
588+
dtype: float64
532589

533590
See :ref:`Exponentially weighted moment functions <stats.moments.exponentially_weighted>` for details. (:issue:`7912`)
534591

doc/source/whatsnew/v0.18.0.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ And multiple aggregations
8686

8787
.. ipython:: python
8888

89-
r.agg({'A' : {'ra' : ['mean','std']},
90-
'B' : {'rb' : ['mean','std']}})
89+
r.agg({'A' : ['mean','std'],
90+
'B' : ['mean','std']})
9191

9292
.. _whatsnew_0180.enhancements.other:
9393

@@ -239,15 +239,17 @@ Deprecations
239239
2 0.5
240240
dtype: float64
241241

242-
- The the ``freq`` and ``how`` arguments to the ``.rolling``, ``.expanding``, and ``.ewm`` (new) functions are deprecated, and will be removed in a future version. (:issue:`11603`)
242+
- The the ``freq`` and ``how`` arguments to the ``.rolling``, ``.expanding``, and ``.ewm`` (new) functions are deprecated, and will be removed in a future version. You can simply resample the input prior to creating a window function. (:issue:`11603`).
243+
244+
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',how='max').rolling(window=5).max()``, which first resamples the data to daily data, then provides a rolling 5 day window.
243245

244246
.. _whatsnew_0180.prior_deprecations:
245247

246248
Removal of prior version deprecations/changes
247249
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248250

249-
- Removal of ``rolling_corr_parwise`` in favor of ``.rolling().corr(pairwise=True)`` (:issue:`4950`)
250-
- Removal of ``expanding_corr_parwise`` in favor of ``.expanding().corr(pairwise=True)`` (:issue:`4950`)
251+
- Removal of ``rolling_corr_pairwise`` in favor of ``.rolling().corr(pairwise=True)`` (:issue:`4950`)
252+
- Removal of ``expanding_corr_pairwise`` in favor of ``.expanding().corr(pairwise=True)`` (:issue:`4950`)
251253

252254

253255

pandas/core/base.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,10 @@ def _gotitem(self, key, ndim, subset=None):
358358
"""
359359

360360
_see_also_template = """
361-
362361
See also
363362
--------
364-
`pandas.Series.%(name)s`
365-
`pandas.DataFrame.%(name)s`
363+
pandas.Series.%(name)s
364+
pandas.DataFrame.%(name)s
366365
"""
367366

368367
def aggregate(self, func, *args, **kwargs):
@@ -422,7 +421,7 @@ def _aggregate(self, arg, *args, **kwargs):
422421
else:
423422
for col, agg_how in compat.iteritems(arg):
424423
colg = self._gotitem(col, ndim=1)
425-
result[col] = colg.aggregate(agg_how, _level=(_level or 0) + 1)
424+
result[col] = colg.aggregate(agg_how, _level=None)
426425
keys.append(col)
427426

428427
if isinstance(list(result.values())[0], com.ABCDataFrame):
@@ -451,12 +450,16 @@ def _aggregate_multiple_funcs(self, arg, _level):
451450
if self.axis != 0:
452451
raise NotImplementedError("axis other than 0 is not supported")
453452

454-
obj = self._obj_with_exclusions
453+
if self._selected_obj.ndim == 1:
454+
obj = self._selected_obj
455+
else:
456+
obj = self._obj_with_exclusions
457+
455458
results = []
456459
keys = []
457460

458461
# degenerate case
459-
if obj.ndim == 1:
462+
if obj.ndim==1:
460463
for a in arg:
461464
try:
462465
colg = self._gotitem(obj.name, ndim=1, subset=obj)

0 commit comments

Comments
 (0)