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