Skip to content

Commit

Permalink
Inherit __array__ from ExplicitlyIndexed
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Aug 5, 2022
1 parent 201eeba commit 0753803
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,13 @@ class ExplicitlyIndexed:

__slots__ = ()

def __array__(self, dtype=None):
return np.asarray(self.get_duck_array(), dtype=dtype)


class ExplicitlyIndexedNDArrayMixin(NDArrayMixin, ExplicitlyIndexed):
__slots__ = ()

def __array__(self, dtype=None):
return np.asarray(self.get_duck_array(), dtype=dtype)

def get_duck_array(self):
key = BasicIndexer((slice(None),) * self.ndim)
return self[key]
Expand All @@ -465,7 +465,7 @@ def __init__(self, array, indexer_cls=BasicIndexer):
self.indexer_cls = indexer_cls

def __array__(self, dtype=None):
return np.asarray(self.array, dtype=dtype)
return np.asarray(self.get_duck_array(), dtype=dtype)

def get_duck_array(self):
return self.array.get_duck_array()
Expand Down Expand Up @@ -531,9 +531,6 @@ def shape(self) -> tuple[int, ...]:
shape.append(k.size)
return tuple(shape)

def __array__(self, dtype=None):
return np.asarray(self.get_duck_array(), dtype=dtype)

def get_duck_array(self):
array = as_indexable(self.array)
array = array[self.key]
Expand Down Expand Up @@ -646,9 +643,6 @@ def _ensure_copied(self):
self.array = as_indexable(np.array(self.array))
self._copied = True

def __array__(self, dtype=None):
return np.asarray(self.array, dtype=dtype)

def get_duck_array(self):
return self.array.get_duck_array()

Expand Down

0 comments on commit 0753803

Please sign in to comment.