diff --git a/xarray/namedarray/core.py b/xarray/namedarray/core.py index 43b6a766483..1f893d21c82 100644 --- a/xarray/namedarray/core.py +++ b/xarray/namedarray/core.py @@ -20,27 +20,25 @@ from xarray.core import dtypes from xarray.namedarray.utils import ( Default, + DuckArray, _arrayfunction_or_api, _AttrsLike, _Chunks, _default, - _Array, - DuckArray, - duckarray, _Dim, _Dims, _DimsLike, _DType_co, _IntOrUnknown, - _Shape, - _DType_co, _ScalarType, _ScalarType_co, + _Shape, _ShapeType, _ShapeType_co, - _SupportsReal, - _SupportsImag, _sparsearrayfunction_or_api, + _SupportsImag, + _SupportsReal, + duckarray, is_chunked_duck_array, is_duck_dask_array, to_0d_object_array, @@ -126,7 +124,6 @@ def from_array( return NamedArray(dims, data, attrs) if isinstance(data, _arrayfunction_or_api): - return NamedArray(dims, data, attrs) else: if isinstance(data, tuple): diff --git a/xarray/namedarray/utils.py b/xarray/namedarray/utils.py index 6bd62a0b17f..8b5320ad34b 100644 --- a/xarray/namedarray/utils.py +++ b/xarray/namedarray/utils.py @@ -13,8 +13,8 @@ SupportsIndex, TypeVar, Union, - runtime_checkable, overload, + runtime_checkable, ) import numpy as np @@ -54,6 +54,7 @@ _ScalarType = TypeVar("_ScalarType", bound=np.generic) _ScalarType_co = TypeVar("_ScalarType_co", bound=np.generic, covariant=True) + # A protocol for anything with the dtype attribute @runtime_checkable class _SupportsDType(Protocol[_DType_co]): @@ -97,6 +98,7 @@ class _SupportsImag(Protocol[_T_co]): def imag(self) -> _T_co: ... + _SupportsReal[_ScalarType]