From 07538030a4bf71d090e51e4f0548669d539ae117 Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 5 Aug 2022 15:27:51 -0600 Subject: [PATCH] Inherit __array__ from ExplicitlyIndexed --- xarray/core/indexing.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index c70229312ed..749e3a916ec 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -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] @@ -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() @@ -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] @@ -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()