diff --git a/xarray/namedarray/pycompat.py b/xarray/namedarray/pycompat.py index f04e290344e..16136b632c3 100644 --- a/xarray/namedarray/pycompat.py +++ b/xarray/namedarray/pycompat.py @@ -161,14 +161,15 @@ def to_duck_array( from xarray.core.indexing import ExplicitlyIndexed from xarray.namedarray.parallelcompat import get_chunked_array_type + if isinstance(data, ExplicitlyIndexed): + return data.get_duck_array() # type: ignore[no-untyped-call, no-any-return] + if is_chunked_array(data): chunkmanager = get_chunked_array_type(data) loaded_data, *_ = chunkmanager.compute(data, **kwargs) # type: ignore[var-annotated] return loaded_data - if isinstance(data, ExplicitlyIndexed): - return data.get_duck_array() # type: ignore[no-untyped-call, no-any-return] - elif is_duck_array(data): + if is_duck_array(data): return data else: - return np.asarray(data) # type: ignore[return-value] + return np.asarray(data)