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

Function asarray

xarray/core/duck_array_ops.py:272–288  ·  view source on GitHub ↗
(data, xp=np, dtype=None)

Source from the content-addressed store, hash-verified

270
271
272def asarray(data, xp=np, dtype=None):
273 if is_duck_array(data):
274 converted = data
275 elif is_allowed_extension_array_dtype(dtype):
276 # data may or may not be an ExtensionArray, so we can't rely on
277 # np.asarray to call our NEP-18 handler; gotta hook it ourselves
278 converted = PandasExtensionArray(as_extension_array(data, dtype))
279 else:
280 converted = xp.asarray(data)
281
282 if dtype is None or converted.dtype == dtype:
283 return converted
284
285 if xp is np or not hasattr(xp, "astype"):
286 return converted.astype(dtype)
287 else:
288 return xp.astype(converted, dtype)
289
290
291def as_shared_dtype(scalars_or_arrays, xp=None):

Callers 15

encode_cf_datetimeFunction · 0.90
encode_cf_timedeltaFunction · 0.90
isnullFunction · 0.85
as_shared_dtypeFunction · 0.85
lazy_array_equivFunction · 0.85
allclose_or_equivFunction · 0.85
array_equivFunction · 0.85
array_notnull_equivFunction · 0.85
whereFunction · 0.85
fFunction · 0.85

Calls 5

is_duck_arrayFunction · 0.90
as_extension_arrayFunction · 0.90
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…