Skip to content
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

[feature request] __iter__() for rolling-window on datasets #3452

Open
Hoeze opened this issue Oct 26, 2019 · 2 comments
Open

[feature request] __iter__() for rolling-window on datasets #3452

Hoeze opened this issue Oct 26, 2019 · 2 comments

Comments

@Hoeze
Copy link

Hoeze commented Oct 26, 2019

Currently, rolling() on a dataset does not return an iterator:

MCVE Code Sample

arr = xr.DataArray(np.arange(0, 7.5, 0.5).reshape(3, 5),
    dims=('x', 'y'))

r = arr.to_dataset(name="test").rolling(y=3)
for label, arr_window in r:
    print(label)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-b1703cb71c1e> in <module>
      3 
      4 r = arr.to_dataset(name="test").rolling(y=3)
----> 5 for label, arr_window in r:
      6     print(label)

TypeError: 'DatasetRolling' object is not iterable

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 5.3.7-arch1-1-ARCH machine: x86_64 processor: byteorder: little LC_ALL: None LANG: de_DE.UTF-8 LOCALE: de_DE.UTF-8 libhdf5: 1.10.4 libnetcdf: None

xarray: 0.13.0
pandas: 0.24.2
numpy: 1.16.4
scipy: 1.3.0
netCDF4: None
pydap: None
h5netcdf: 0.7.4
h5py: 2.9.0
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.1.0
distributed: 2.1.0
matplotlib: 3.1.1
cartopy: None
seaborn: 0.9.0
numbagg: None
setuptools: 41.4.0
pip: 19.1.1
conda: None
pytest: None
IPython: 7.8.0
sphinx: None

@dcherian
Copy link
Contributor

You should look at rolling.construct. It could be a lot more efficient than iterating.

@Hoeze
Copy link
Author

Hoeze commented Nov 1, 2019

Thanks for your suggestion @dcherian

You should look at rolling.construct. It could be a lot more efficient than iterating.

I think iterating over rolling.construct() should then be equally efficient compared to some rolling.__iter__() function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants