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

iris.util.rolling_window does not support Dask arrays #5774

Closed
bouweandela opened this issue Feb 22, 2024 · 0 comments · Fixed by #5775
Closed

iris.util.rolling_window does not support Dask arrays #5774

bouweandela opened this issue Feb 22, 2024 · 0 comments · Fixed by #5775

Comments

@bouweandela
Copy link
Member

🐛 Bug Report

According to the docstring of iris.util.rolling_window it maintains laziness when called, but actually passing in a Dask array leads to a crash.

How To Reproduce

Steps to reproduce the behaviour:

In [1]: import dask.array as da

In [2]: from iris.util import rolling_window

In [3]: x = da.arange(10).reshape((2, 5))

In [4]: rolling_window(x, 3).compute()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 rolling_window(x, 3)

File ~/src/scitools/iris/lib/iris/util.py:337, in rolling_window(a, window, step, axis)
    334 num_windows = (a.shape[axis] - window + step) // step
    335 shape = a.shape[:axis] + (num_windows, window) + a.shape[axis + 1 :]
    336 strides = (
--> 337     a.strides[:axis]
    338     + (step * a.strides[axis], a.strides[axis])
    339     + a.strides[axis + 1 :]
    340 )
    341 rw = np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)
    342 if ma.isMaskedArray(a):

AttributeError: 'Array' object has no attribute 'strides'

Expected behaviour

Instead of a crash, I would expect an output array

In [1]: import dask.array as da

In [2]: from iris.util import rolling_window

In [3]: x = da.arange(10).reshape((2, 5))

In [4]: rolling_window(x, 3).compute()
Out[4]: 
array([[[0, 1, 2],
        [1, 2, 3],
        [2, 3, 4]],

       [[5, 6, 7],
        [6, 7, 8],
        [7, 8, 9]]])

Environment

  • OS & Version: Ubuntu 23.10
  • Iris Version: 3.8.0.dev125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants