Skip to content

Commit 6187d80

Browse files
authored
Fix negative slicing of Zarr arrays (#8674)
* Fix negative slicing of Zarr arrays Closes #8252 Closes #3921 * Cleanup
1 parent b9e129f commit 6187d80

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Bug fixes
5959
By `Tom Nicholas <https://github.com/TomNicholas>`_.
6060
- Ensure :py:meth:`DataArray.unstack` works when wrapping array API-compliant classes. (:issue:`8666`, :pull:`8668`)
6161
By `Tom Nicholas <https://github.com/TomNicholas>`_.
62+
- Fix negative slicing of Zarr arrays without dask installed. (:issue:`8252`)
63+
By `Deepak Cherian <https://github.com/dcherian>`_.
6264
- Preserve chunks when writing time-like variables to zarr by enabling lazy CF
6365
encoding of time-like variables (:issue:`7132`, :issue:`8230`, :issue:`8432`,
6466
:pull:`8575`). By `Spencer Clark <https://github.com/spencerkclark>`_ and

xarray/backends/zarr.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,23 @@ def get_array(self):
8686
def _oindex(self, key):
8787
return self._array.oindex[key]
8888

89+
def _vindex(self, key):
90+
return self._array.vindex[key]
91+
92+
def _getitem(self, key):
93+
return self._array[key]
94+
8995
def __getitem__(self, key):
9096
array = self._array
9197
if isinstance(key, indexing.BasicIndexer):
92-
return array[key.tuple]
98+
method = self._getitem
9399
elif isinstance(key, indexing.VectorizedIndexer):
94-
return array.vindex[
95-
indexing._arrayize_vectorized_indexer(key, self.shape).tuple
96-
]
97-
else:
98-
assert isinstance(key, indexing.OuterIndexer)
99-
return indexing.explicit_indexing_adapter(
100-
key, array.shape, indexing.IndexingSupport.VECTORIZED, self._oindex
101-
)
100+
method = self._vindex
101+
elif isinstance(key, indexing.OuterIndexer):
102+
method = self._oindex
103+
return indexing.explicit_indexing_adapter(
104+
key, array.shape, indexing.IndexingSupport.VECTORIZED, method
105+
)
102106

103107
# if self.ndim == 0:
104108
# could possibly have a work-around for 0d data here

0 commit comments

Comments
 (0)