Skip to content

Commit f2514c7

Browse files
committed
Add get_duck_array to AbstractArray
Clean up short_array_repr.
1 parent 536648a commit f2514c7

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

xarray/core/common.py

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ def __complex__(self: Any) -> complex:
155155
def __array__(self: Any, dtype: DTypeLike = None) -> np.ndarray:
156156
return np.asarray(self.values, dtype=dtype)
157157

158+
def get_duck_array(self):
159+
return self.data
160+
158161
def __repr__(self) -> str:
159162
return formatting.array_repr(self)
160163

xarray/core/formatting.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,9 @@ def limit_lines(string: str, *, limit: int):
517517

518518

519519
def short_array_repr(array):
520-
from .dataarray import DataArray
521-
from .variable import Variable
520+
from .common import AbstractArray
522521

523-
if isinstance(array, DataArray):
524-
array = array._variable.data
525-
if isinstance(array, Variable):
526-
array = array.data
527-
if isinstance(array, ExplicitlyIndexed):
522+
if isinstance(array, (ExplicitlyIndexed, AbstractArray)):
528523
array = array.get_duck_array()
529524
if not is_duck_array(array):
530525
array = np.asarray(array)

0 commit comments

Comments
 (0)