-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
boundary options for rolling.construct #3587
base: main
Are you sure you want to change the base?
Changes from 5 commits
0cdcc88
b895c0f
730be82
4b3c6db
e40d78d
c134e78
dfabeda
5676037
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 |
---|---|---|
|
@@ -193,7 +193,7 @@ def __iter__(self): | |
|
||
yield (label, window) | ||
|
||
def construct(self, window_dim, stride=1, fill_value=dtypes.NA): | ||
def construct(self, window_dim, stride=1, fill_value=dtypes.NA, mode=None): | ||
""" | ||
Convert this rolling object to xr.DataArray, | ||
where the window dimension is stacked as a new dimension | ||
|
@@ -206,6 +206,11 @@ def construct(self, window_dim, stride=1, fill_value=dtypes.NA): | |
Size of stride for the rolling window. | ||
fill_value: optional. Default dtypes.NA | ||
Filling value to match the dimension size. | ||
mode: optional. Default None | ||
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.
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.
|
||
One of None | 'edge' | 'reflect' | 'symmetric' | 'wrap' | ||
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. Maybe the default should be |
||
For the details of the mode, see | ||
https://docs.scipy.org/doc/numpy/reference/generated/numpy.pad.html | ||
If it is not None, fill_value is ignored. | ||
|
||
Returns | ||
------- | ||
|
@@ -234,7 +239,12 @@ def construct(self, window_dim, stride=1, fill_value=dtypes.NA): | |
from .dataarray import DataArray | ||
|
||
window = self.obj.variable.rolling_window( | ||
self.dim, self.window, window_dim, self.center, fill_value=fill_value | ||
self.dim, | ||
self.window, | ||
window_dim, | ||
self.center, | ||
fill_value=fill_value, | ||
mode=mode, | ||
) | ||
result = DataArray( | ||
window, dims=self.obj.dims + (window_dim,), coords=self.obj.coords | ||
|
@@ -466,7 +476,7 @@ def _numpy_or_bottleneck_reduce( | |
**kwargs, | ||
) | ||
|
||
def construct(self, window_dim, stride=1, fill_value=dtypes.NA): | ||
def construct(self, window_dim, stride=1, fill_value=dtypes.NA, mode=None): | ||
""" | ||
Convert this rolling object to xr.Dataset, | ||
where the window dimension is stacked as a new dimension | ||
|
@@ -479,6 +489,10 @@ def construct(self, window_dim, stride=1, fill_value=dtypes.NA): | |
size of stride for the rolling window. | ||
fill_value: optional. Default dtypes.NA | ||
Filling value to match the dimension size. | ||
mode: optional. Default None | ||
One of None | 'edge' | 'reflect' | 'symmetric' | 'wrap' | ||
For the details of the mode, see | ||
https://docs.scipy.org/doc/numpy/reference/generated/numpy.pad.html | ||
|
||
Returns | ||
------- | ||
|
@@ -491,7 +505,7 @@ def construct(self, window_dim, stride=1, fill_value=dtypes.NA): | |
for key, da in self.obj.data_vars.items(): | ||
if self.dim in da.dims: | ||
dataset[key] = self.rollings[key].construct( | ||
window_dim, fill_value=fill_value | ||
window_dim, fill_value=fill_value, mode=mode | ||
) | ||
else: | ||
dataset[key] = da | ||
|
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.
Is this the right version number for dask? I can't find a 1.7 release.
Also note that we only need to support versions of dask < 6 months old, per http://xarray.pydata.org/en/stable/installing.html. If we can just delete the old code entirely, that might be cleaner.
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.
Dask API page says it came at the version 1.7, but I just noticed this doc is just copied from numpy...
I'll fix it.