Skip to content

Commit 31921fa

Browse files
Ray Bellshoyer
Ray Bell
authored andcommitted
DOC: Added examples to rolling.py (#1574)
* Added examples to doc Added a comprehensive rolling example * Revert back to original rolling.py Removed my example * DOC: added an example in def rolling() * Revert back to latest rolling.py * DOC: rolling.py example Shed a few lines of my example * Update common.py cleaned up rolling example * DOC: rolling.py example Extended the description of the rolling.py example * DOC: rolling.py example Realized I didn't need to create a variable, as I can simply show the output * DOC: add rolling.py example Cleaned up the example text to add a comment in the middle * formatting
1 parent 3fb5cbb commit 31921fa

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

xarray/core/common.py

+27
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,33 @@ def rolling(self, min_periods=None, center=False, **windows):
474474
Returns
475475
-------
476476
rolling : type of input argument
477+
478+
Examples
479+
--------
480+
Create rolling seasonal average of monthly data e.g. DJF, JFM, ..., SON:
481+
482+
>>> da = xr.DataArray(np.linspace(0,11,num=12),
483+
... coords=[pd.date_range('15/12/1999',
484+
... periods=12, freq=pd.DateOffset(months=1))],
485+
... dims='time')
486+
>>> da
487+
<xarray.DataArray (time: 12)>
488+
array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.])
489+
Coordinates:
490+
* time (time) datetime64[ns] 1999-12-15 2000-01-15 2000-02-15 ...
491+
>>> da.rolling(time=3).mean()
492+
<xarray.DataArray (time: 12)>
493+
array([ nan, nan, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
494+
Coordinates:
495+
* time (time) datetime64[ns] 1999-12-15 2000-01-15 2000-02-15 ...
496+
497+
Remove the NaNs using ``dropna()``:
498+
499+
>>> da.rolling(time=3).mean().dropna('time')
500+
<xarray.DataArray (time: 10)>
501+
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
502+
Coordinates:
503+
* time (time) datetime64[ns] 2000-02-15 2000-03-15 2000-04-15 ...
477504
"""
478505

479506
return self._rolling_cls(self, min_periods=min_periods,

0 commit comments

Comments
 (0)