Skip to content

Commit

Permalink
Add Examples to DataArrayRolling.reduce
Browse files Browse the repository at this point in the history
* Adds two examples to DataArrayRolling.reduce(); the second example
  shows the interaction of reduce() and min_periods
  • Loading branch information
kmsquire committed May 17, 2019
1 parent bd78b7f commit a59d6f6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,29 @@ def reduce(self, func, **kwargs):
-------
reduced : DataArray
Array with summarized data.
Examples
--------
>>> da = DataArray(np.arange(8).reshape(2, 4), dims=('a', 'b'))
>>>
>>> rolling = da.rolling(b=3)
>>> rolling.construct('window_dim')
<xarray.DataArray (a: 2, b: 4, window_dim: 3)>
array([[[np.nan, np.nan, 0], [np.nan, 0, 1], [0, 1, 2], [1, 2, 3]],
[[np.nan, np.nan, 4], [np.nan, 4, 5], [4, 5, 6], [5, 6, 7]]])
Dimensions without coordinates: a, b, window_dim
>>>
>>> rolling.reduce(np.sum)
<xarray.DataArray (a: 2, b: 4)>
array([[nan, nan, 3., 6.],
[nan, nan, 15., 18.]])
Dimensions without coordinates: a, b
>>>
>>> rolling = da.rolling(b=3, min_periods=1)
>>> rolling.reduce(np.nansum)
<xarray.DataArray (a: 2, b: 4)>
array([[ 0., 1., 3., 6.],
[ 4., 9., 15., 18.]])
"""
rolling_dim = utils.get_temp_dimname(self.obj.dims, '_rolling_dim')
windows = self.construct(rolling_dim)
Expand Down

0 comments on commit a59d6f6

Please sign in to comment.