MCPcopy
hub / github.com/pydata/xarray / is_duck_array

Function is_duck_array

xarray/namedarray/utils.py:78–91  ·  view source on GitHub ↗
(value: Any)

Source from the content-addressed store, hash-verified

76
77
78def is_duck_array(value: Any) -> TypeGuard[duckarray[Any, Any]]:
79 # TODO: replace is_duck_array with runtime checks via _arrayfunction_or_api protocol on
80 # python 3.12 and higher (see https://github.com/pydata/xarray/issues/8696#issuecomment-1924588981)
81 if isinstance(value, np.ndarray):
82 return True
83 return (
84 hasattr(value, "ndim")
85 and hasattr(value, "shape")
86 and hasattr(value, "dtype")
87 and (
88 (hasattr(value, "__array_function__") and hasattr(value, "__array_ufunc__"))
89 or hasattr(value, "__array_namespace__")
90 )
91 )
92
93
94def is_duck_dask_array(x: duckarray[Any, Any]) -> TypeGuard[DaskArray]:

Callers 15

decode_cf_variableFunction · 0.90
is_chunked_arrayFunction · 0.90
to_duck_arrayFunction · 0.90
_validate_indexersMethod · 0.90
asarrayFunction · 0.90
whereFunction · 0.90
dataMethod · 0.90
_validate_indexersMethod · 0.90
_broadcast_compat_dataFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…