(fill_value, unit, error, dtype)
| 1467 | ) |
| 1468 | @pytest.mark.parametrize("fill_value", (np.nan, 10.2)) |
| 1469 | def 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 | |
| 1499 | def test_dot_dataarray(dtype): |
nothing calls this directly
no test coverage detected
searching dependent graphs…