|
36 | 36 | infix_dims, |
37 | 37 | maybe_coerce_to_str, |
38 | 38 | ) |
| 39 | +from xarray.namedarray._typing import _arrayfunction_or_api |
39 | 40 | from xarray.namedarray.core import NamedArray |
40 | 41 | from xarray.namedarray.parallelcompat import get_chunked_array_type |
41 | | -from xarray.namedarray.pycompat import ( |
42 | | - integer_types, |
43 | | - is_0d_dask_array, |
44 | | - is_chunked_array, |
45 | | -) |
| 42 | +from xarray.namedarray.pycompat import integer_types, is_0d_dask_array, is_chunked_array |
46 | 43 | from xarray.namedarray.utils import ( |
47 | 44 | either_dict_or_kwargs, |
48 | 45 | is_dict_like, |
49 | | - is_duck_array, |
50 | 46 | is_duck_dask_array, |
51 | 47 | ) |
52 | 48 |
|
@@ -411,7 +407,7 @@ def data(self): |
411 | 407 | Variable.as_numpy |
412 | 408 | Variable.values |
413 | 409 | """ |
414 | | - if is_duck_array(self._data): |
| 410 | + if isinstance(self._data, _arrayfunction_or_api): |
415 | 411 | return self._data |
416 | 412 | elif isinstance(self._data, indexing.ExplicitlyIndexed): |
417 | 413 | return self._data.get_duck_array() |
@@ -636,7 +632,7 @@ def _validate_indexers(self, key): |
636 | 632 | for dim, k in zip(self.dims, key): |
637 | 633 | if not isinstance(k, BASIC_INDEXING_TYPES): |
638 | 634 | if not isinstance(k, Variable): |
639 | | - if not is_duck_array(k): |
| 635 | + if not isinstance(k, _arrayfunction_or_api): |
640 | 636 | k = np.asarray(k) |
641 | 637 | if k.ndim > 1: |
642 | 638 | raise IndexError( |
@@ -681,7 +677,7 @@ def _broadcast_indexes_outer(self, key): |
681 | 677 | if isinstance(k, Variable): |
682 | 678 | k = k.data |
683 | 679 | if not isinstance(k, BASIC_INDEXING_TYPES): |
684 | | - if not is_duck_array(k): |
| 680 | + if not isinstance(k, _arrayfunction_or_api): |
685 | 681 | k = np.asarray(k) |
686 | 682 | if k.size == 0: |
687 | 683 | # Slice by empty list; numpy could not infer the dtype |
@@ -940,7 +936,7 @@ def load(self, **kwargs): |
940 | 936 | self._data = as_compatible_data(loaded_data) |
941 | 937 | elif isinstance(self._data, ExplicitlyIndexed): |
942 | 938 | self._data = self._data.get_duck_array() |
943 | | - elif not is_duck_array(self._data): |
| 939 | + elif not isinstance(self._data, _arrayfunction_or_api): |
944 | 940 | self._data = np.asarray(self._data) |
945 | 941 | return self |
946 | 942 |
|
|
0 commit comments