Skip to content

Commit

Permalink
Fix negative slicing of Zarr arrays (#8674)
Browse files Browse the repository at this point in the history
* Fix negative slicing of Zarr arrays

Closes #8252
Closes #3921

* Cleanup
  • Loading branch information
dcherian authored Feb 10, 2024
1 parent b9e129f commit 6187d80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Bug fixes
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Ensure :py:meth:`DataArray.unstack` works when wrapping array API-compliant classes. (:issue:`8666`, :pull:`8668`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Fix negative slicing of Zarr arrays without dask installed. (:issue:`8252`)
By `Deepak Cherian <https://github.com/dcherian>`_.
- Preserve chunks when writing time-like variables to zarr by enabling lazy CF
encoding of time-like variables (:issue:`7132`, :issue:`8230`, :issue:`8432`,
:pull:`8575`). By `Spencer Clark <https://github.com/spencerkclark>`_ and
Expand Down
22 changes: 13 additions & 9 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,23 @@ def get_array(self):
def _oindex(self, key):
return self._array.oindex[key]

def _vindex(self, key):
return self._array.vindex[key]

def _getitem(self, key):
return self._array[key]

def __getitem__(self, key):
array = self._array
if isinstance(key, indexing.BasicIndexer):
return array[key.tuple]
method = self._getitem
elif isinstance(key, indexing.VectorizedIndexer):
return array.vindex[
indexing._arrayize_vectorized_indexer(key, self.shape).tuple
]
else:
assert isinstance(key, indexing.OuterIndexer)
return indexing.explicit_indexing_adapter(
key, array.shape, indexing.IndexingSupport.VECTORIZED, self._oindex
)
method = self._vindex
elif isinstance(key, indexing.OuterIndexer):
method = self._oindex
return indexing.explicit_indexing_adapter(
key, array.shape, indexing.IndexingSupport.VECTORIZED, method
)

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

0 comments on commit 6187d80

Please sign in to comment.