Closed
Description
What happened?
ds = xr.Dataset(
{"z": (("t", "p", "y", "x"), np.ones((1, 1, 31, 40)))},
)
ds = ds.chunk()
subset = ds.isel(t=[0], p=0).z[:, ::10, ::10][:, ::-1, :] # breaks
# subset = ds.isel(t=[0]).isel(p=0).z[:, ::10, ::10][:, ::-1, :] # works
display(subset)
print(subset.sizes)
print(subset.load().sizes)
xarray/tests/test_backends.py:827 (TestDask.test_outer_indexing_reversed)
self = <xarray.tests.test_backends.TestDask object at 0x7f2da44c2ff0>
def test_outer_indexing_reversed(self) -> None:
# regression test for GH6560
ds = xr.Dataset(
{"z": (("t", "p", "y", "x"), np.ones((1, 1, 31, 40)))},
)
with self.roundtrip(ds) as on_disk:
> subset = on_disk.isel(t=[0], p=0).z[:, ::10, ::10][:, ::-1, :]
/home/kai/python/projects/xarray/xarray/tests/test_backends.py:835:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/kai/python/projects/xarray/xarray/core/dataset.py:2764: in isel
var = var.isel(var_indexers)
/home/kai/python/projects/xarray/xarray/core/variable.py:1032: in isel
return self[key]
/home/kai/python/projects/xarray/xarray/core/variable.py:782: in __getitem__
return self._finalize_indexing_result(dims, data)
/home/kai/python/projects/xarray/xarray/core/variable.py:786: in _finalize_indexing_result
return self._replace(dims=dims, data=data)
/home/kai/python/projects/xarray/xarray/core/variable.py:938: in _replace
return type(self)(dims, data, attrs, encoding, fastpath=True)
/home/kai/python/projects/xarray/xarray/core/variable.py:365: in __init__
super().__init__(
/home/kai/python/projects/xarray/xarray/namedarray/core.py:264: in __init__
self._dims = self._parse_dimensions(dims)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[AttributeError("'Variable' object has no attribute '_dims'") raised in repr()] Variable object at 0x7f2d5c6c6380>
dims = ('t', 'y', 'x')
def _parse_dimensions(self, dims: _DimsLike) -> _Dims:
dims = (dims,) if isinstance(dims, str) else tuple(dims)
if len(dims) != self.ndim:
> raise ValueError(
f"dimensions {dims} must have the same length as the "
f"number of data dimensions, ndim={self.ndim}"
)
E ValueError: dimensions ('t', 'y', 'x') must have the same length as the number of data dimensions, ndim=4
/home/kai/python/projects/xarray/xarray/namedarray/core.py:508: ValueError
What did you expect to happen?
No response
Minimal Complete Verifiable Example
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Anything else we need to know?
No response