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

Function where

xarray/core/duck_array_ops.py:407–419  ·  view source on GitHub ↗

Three argument where() with better dtype promotion rules.

(condition, x, y)

Source from the content-addressed store, hash-verified

405
406
407def where(condition, x, y):
408 """Three argument where() with better dtype promotion rules."""
409 xp = get_array_namespace(condition, x, y)
410
411 dtype = xp.bool_ if hasattr(xp, "bool_") else xp.bool
412 if not is_duck_array(condition):
413 condition = asarray(condition, dtype=dtype, xp=xp)
414 else:
415 condition = astype(condition, dtype=dtype, xp=xp)
416
417 promoted_x, promoted_y = as_shared_dtype([x, y], xp=xp)
418
419 return xp.where(condition, promoted_x, promoted_y)
420
421
422def where_method(data, cond, other=dtypes.NA):

Callers 8

factorizeMethod · 0.90
_maybe_null_outFunction · 0.90
test_whereFunction · 0.90
where_methodFunction · 0.70
fillnaFunction · 0.70
_datetime_nanreduceFunction · 0.70

Calls 6

get_array_namespaceFunction · 0.90
is_duck_arrayFunction · 0.90
asarrayFunction · 0.85
as_shared_dtypeFunction · 0.85
astypeFunction · 0.70
whereMethod · 0.45

Tested by 3

test_whereFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…