Skip to content

Cube.rolling_window can fail with lazy aux-coords #6639

@pp-mo

Description

@pp-mo

🐛 Bug Report

'rolling_window' on a cube will fail it it has lazy aux-coords that parallel the "rolled" dimension.
Because this line and this one apply a type of indexing that doesn't work with Dask
-- but, heavy hint it probably works to just replace (0, -1) with [0, -1]
(see 'Additional Context' below)

How To Reproduce

dimco = DimCoord(np.arange(12), standard_name="time", units="s")
auxco = AuxCoord(da.arange(12), long_name="x")
cube = Cube(
    np.arange(12),
    dim_coords_and_dims=[(dimco, 0)],
    aux_coords_and_dims=[(auxco, 0)],
)
attempt = cube.rolling_window(coord="time", window=3, aggregator=MEAN)

Result is, ultimately...

Traceback (most recent call last):
  . . .
  File "/home/users/patrick.peglar/git/iris/lib/iris/cube.py", line 4965, in rolling_window
    new_bounds = new_bounds[:, (0, -1)]
                 ~~~~~~~~~~^^^^^^^^^^^^
  File "/data/apps/sss/environments/preproduction-os47/lib/python3.12/site-packages/dask/array/core.py", line 2045, in __getitem__
    index2 = normalize_index(index, self.shape)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/apps/sss/environments/preproduction-os47/lib/python3.12/site-packages/dask/array/slicing.py", line 848, in normalize_index
    check_index(axis, i, d)
  File "/data/apps/sss/environments/preproduction-os47/lib/python3.12/site-packages/dask/array/slicing.py", line 919, in check_index
    elif ind >= dimension or ind < -dimension:
         ^^^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'tuple' and 'int'

Expected behaviour

This operation should be succeed

Additional context

Click to expand this section...

Dask docs here
say "lists/arrays" , but does not include "tuples"

However, given careful reading of Numpy docs here,
it would seem that when applied to a given multidimensional index among others, a tuple or list or 1-D array of integers, should all be valid + produce the same result,
e.g. arr[:, (0, -1)], arr[:, [0, -1]] or arr[:, np.array([0, -1])] -- should all be the same

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Status

    🆕 Candidate

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions