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

Function test_where_dataarray

xarray/tests/test_units.py:1426–1452  ·  view source on GitHub ↗
(fill_value, unit, error, dtype)

Source from the content-addressed store, hash-verified

1424)
1425@pytest.mark.parametrize("fill_value", (np.nan, 10.2))
1426def test_where_dataarray(fill_value, unit, error, dtype):
1427 array = np.linspace(0, 5, 10).astype(dtype) * unit_registry.m
1428
1429 x = xr.DataArray(data=array, dims="x")
1430 cond = x < 5 * unit_registry.m
1431 fill_value = fill_value * unit
1432
1433 if error is not None and not (
1434 np.isnan(fill_value) and not isinstance(fill_value, Quantity)
1435 ):
1436 with pytest.raises(error):
1437 xr.where(cond, x, fill_value)
1438
1439 return
1440
1441 expected = attach_units(
1442 xr.where(
1443 cond,
1444 strip_units(x),
1445 strip_units(convert_units(fill_value, {None: unit_registry.m})),
1446 ),
1447 extract_units(x),
1448 )
1449 actual = xr.where(cond, x, fill_value)
1450
1451 assert_units_equal(expected, actual)
1452 assert_identical(expected, actual)
1453
1454
1455@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 9

assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
convert_unitsFunction · 0.85
extract_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
astypeMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…