Skip to content

Commit

Permalink
Better?
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Mar 16, 2023
1 parent e911e12 commit fb7ccc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 1 addition & 3 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ def __getitem__(self, key):
]
else:
assert isinstance(key, indexing.OuterIndexer)
# Lie about IndexingSupport so that we do
# rewrite negative slices to positive slices
return indexing.explicit_indexing_adapter(
key, array.shape, indexing.IndexingSupport.OUTER, self._oindex
key, array.shape, indexing.IndexingSupport.VECTORIZED, self._oindex
)

# if self.ndim == 0:
Expand Down
22 changes: 18 additions & 4 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NDArrayMixin,
either_dict_or_kwargs,
get_valid_numpy_dtype,
is_scalar,
to_0d_array,
)

Expand Down Expand Up @@ -980,12 +981,25 @@ def _decompose_outer_indexer(
[14, 15, 14],
[ 8, 9, 8]])
"""
if indexing_support == IndexingSupport.VECTORIZED:
return indexer, BasicIndexer(())
assert isinstance(indexer, (OuterIndexer, BasicIndexer))

backend_indexer: list[Any] = []
np_indexer = []

assert isinstance(indexer, (OuterIndexer, BasicIndexer))

if indexing_support == IndexingSupport.VECTORIZED:
for k, s in zip(indexer.tuple, shape):
if isinstance(k, slice):
# If it is a slice, then we will slice it as-is
# (but make its step positive) in the backend,
bk_slice, np_slice = _decompose_slice(k, s)
backend_indexer.append(bk_slice)
np_indexer.append(np_slice)
else:
backend_indexer.append(k)
if not is_scalar(k):
np_indexer.append(slice(None))
return type(indexer)(tuple(backend_indexer)), BasicIndexer(tuple(np_indexer))

# make indexer positive
pos_indexer: list[np.ndarray | int | np.number] = []
for k, s in zip(indexer.tuple, shape):
Expand Down

0 comments on commit fb7ccc9

Please sign in to comment.