-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DOC: Added examples to rolling.py #1574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
1bdda87
973fa61
d378e26
ed1536b
3d0df58
f73baf6
cdc9def
c157dbb
2689560
b7a9296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -474,6 +474,32 @@ def rolling(self, min_periods=None, center=False, **windows): | |
Returns | ||
------- | ||
rolling : type of input argument | ||
|
||
Examples | ||
-------- | ||
Create rolling seasonal average of monthly data e.g. DJF, JFM, ..., SON: | ||
|
||
>>> da = xr.DataArray(np.linspace(0,11,num=12), | ||
coords=[pd.date_range('15/12/1999', | ||
periods=12, freq=pd.DateOffset(months=1))], | ||
dims='time') | ||
>>> da | ||
<xarray.DataArray (time: 12)> | ||
array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) | ||
Coordinates: | ||
* time (time) datetime64[ns] 1999-12-15 2000-01-15 2000-02-15 ... | ||
>>> da_avg = da.rolling(time=3).mean() | ||
>>> da_avg | ||
<xarray.DataArray (time: 12)> | ||
array([ nan, nan, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) | ||
Coordinates: | ||
* time (time) datetime64[ns] 1999-12-15 2000-01-15 2000-02-15 ... | ||
>>> da_avg = da.rolling(time=3).mean().dropna('time') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either add a little more exposition here to make it clear why you're showing this or drop it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to the output of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can definitely add comments in the middle of examples (e.g., see "Example" for
Even though the output is not as clean, my preference is for showing "minimal units" in docstrings so it's entirely clear to users how a function works. That way they'll know to expect NaNs, for example. So you can also include the example using |
||
>>> da_avg | ||
<xarray.DataArray (time: 10)> | ||
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) | ||
Coordinates: | ||
* time (time) datetime64[ns] 2000-02-15 2000-03-15 2000-04-15 ... | ||
""" | ||
|
||
return self._rolling_cls(self, min_periods=min_periods, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
...
to continue a line (notice that this is what thepython
interpreter does).