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

Function to_duck_array

xarray/namedarray/pycompat.py:130–147  ·  view source on GitHub ↗
(data: Any, **kwargs: dict[str, Any])

Source from the content-addressed store, hash-verified

128
129
130def to_duck_array(data: Any, **kwargs: dict[str, Any]) -> duckarray[_ShapeType, _DType]:
131 from xarray.core.indexing import (
132 ExplicitlyIndexed,
133 ImplicitToExplicitIndexingAdapter,
134 )
135 from xarray.namedarray.parallelcompat import get_chunked_array_type
136
137 if is_chunked_array(data):
138 chunkmanager = get_chunked_array_type(data)
139 loaded_data, *_ = chunkmanager.compute(data, **kwargs) # type: ignore[var-annotated]
140 return loaded_data
141
142 if isinstance(data, ExplicitlyIndexed | ImplicitToExplicitIndexingAdapter):
143 return data.get_duck_array() # type: ignore[no-untyped-call, no-any-return]
144 elif is_duck_array(data):
145 return data
146 else:
147 return np.asarray(data) # type: ignore[return-value]
148
149
150async def async_to_duck_array(

Callers 7

loadMethod · 0.90
first_n_itemsFunction · 0.90
last_n_itemsFunction · 0.90
last_itemFunction · 0.90
format_itemsFunction · 0.90
short_array_reprFunction · 0.90
async_to_duck_arrayFunction · 0.85

Calls 5

get_chunked_array_typeFunction · 0.90
is_duck_arrayFunction · 0.90
is_chunked_arrayFunction · 0.85
computeMethod · 0.45
get_duck_arrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…