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

Function test_where_dataset

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

Source from the content-addressed store, hash-verified

1467)
1468@pytest.mark.parametrize("fill_value", (np.nan, 10.2))
1469def test_where_dataset(fill_value, unit, error, dtype):
1470 array1 = np.linspace(0, 5, 10).astype(dtype) * unit_registry.m
1471 array2 = np.linspace(-5, 0, 10).astype(dtype) * unit_registry.m
1472
1473 ds = xr.Dataset(data_vars={"a": ("x", array1), "b": ("x", array2)})
1474 cond = array1 < 2 * unit_registry.m
1475 fill_value = fill_value * unit
1476
1477 if error is not None and not (
1478 np.isnan(fill_value) and not isinstance(fill_value, Quantity)
1479 ):
1480 with pytest.raises(error):
1481 xr.where(cond, ds, fill_value)
1482
1483 return
1484
1485 expected = attach_units(
1486 xr.where(
1487 cond,
1488 strip_units(ds),
1489 strip_units(convert_units(fill_value, {None: unit_registry.m})),
1490 ),
1491 extract_units(ds),
1492 )
1493 actual = xr.where(cond, ds, fill_value)
1494
1495 assert_units_equal(expected, actual)
1496 assert_identical(expected, actual)
1497
1498
1499def test_dot_dataarray(dtype):

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…