Skip to content

Commit e1199a7

Browse files
committed
Update Rolling window operations documentation
* Add a longer description and examples for the `center` and `min_period` parameters to `DataArray.rolling()`
1 parent a59d6f6 commit e1199a7

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

doc/computation.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,34 @@ name of the dimension as a key (e.g. ``y``) and the window size as the value
143143
144144
arr.rolling(y=3)
145145
146-
The label position and minimum number of periods in the rolling window are
147-
controlled by the ``center`` and ``min_periods`` arguments:
146+
Aggregation and summary methods can be applied directly to the ``Rolling``
147+
object:
148148

149149
.. ipython:: python
150150
151-
arr.rolling(y=3, min_periods=2, center=True)
151+
r = arr.rolling(y=3)
152+
r.reduce(np.std)
153+
r.mean()
152154
153-
Aggregation and summary methods can be applied directly to the ``Rolling`` object:
155+
Aggregation results are at the end of each window by default, but can be
156+
centered by passing ``center=True`` when constructing the ``Rolling`` object:
154157

155158
.. ipython:: python
156159
157-
r = arr.rolling(y=3)
160+
r = arr.rolling(y=3, center=True)
161+
r.mean()
162+
163+
As can be seen above, aggregations of windows which overlap the border of the
164+
array produce ``nan``s. Setting ``min_periods`` in the call to ``rolling``
165+
changes the minimum number of observations within the window required to have
166+
a value when aggregating:
167+
168+
.. ipython:: python
169+
170+
r = arr.rolling(y=3, min_periods=2)
171+
r.mean()
172+
r = arr.rolling(y=3, center=True, min_periods=2)
158173
r.mean()
159-
r.reduce(np.std)
160174
161175
Note that rolling window aggregations are faster when bottleneck_ is installed.
162176

0 commit comments

Comments
 (0)