Skip to content

Commit

Permalink
delete unnecessary _indexing_array_and_key method
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 committed Mar 18, 2024
1 parent 2b0888c commit bd26644
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,24 +1450,6 @@ def __init__(self, array):
)
self.array = array

def _indexing_array_and_key(self, key):
if isinstance(key, OuterIndexer):
array = self.array
key = _outer_to_numpy_indexer(key, self.array.shape)
elif isinstance(key, VectorizedIndexer):
array = NumpyVIndexAdapter(self.array)
key = key.tuple
elif isinstance(key, BasicIndexer):
array = self.array
# We want 0d slices rather than scalars. This is achieved by
# appending an ellipsis (see
# https://numpy.org/doc/stable/reference/arrays.indexing.html#detailed-notes).
key = key.tuple + (Ellipsis,)
else:
raise TypeError(f"unexpected key type: {type(key)}")

return array, key

def transpose(self, order):
return self.array.transpose(order)

Expand All @@ -1481,7 +1463,12 @@ def _vindex_get(self, key):

def __getitem__(self, key):
self._check_and_raise_if_non_basic_indexer(key)
array, key = self._indexing_array_and_key(key)

array = self.array
# We want 0d slices rather than scalars. This is achieved by
# appending an ellipsis (see
# https://numpy.org/doc/stable/reference/arrays.indexing.html#detailed-notes).
key = key.tuple + (Ellipsis,)
return array[key]

def _safe_setitem(self, array, key, value):
Expand All @@ -1507,7 +1494,11 @@ def _vindex_set(self, key, value):

def __setitem__(self, key, value):
self._check_and_raise_if_non_basic_indexer(key)
array, key = self._indexing_array_and_key(key)
array = self.array
# We want 0d slices rather than scalars. This is achieved by
# appending an ellipsis (see
# https://numpy.org/doc/stable/reference/arrays.indexing.html#detailed-notes).
key = key.tuple + (Ellipsis,)
self._safe_setitem(array, key, value)


Expand Down

0 comments on commit bd26644

Please sign in to comment.