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

Fix negative slicing of Zarr arrays #8674

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading