(variant, dtype)
| 426 | ), |
| 427 | ) |
| 428 | def test_apply_ufunc_dataset(variant, dtype): |
| 429 | variants = { |
| 430 | "data": (unit_registry.m, 1, 1), |
| 431 | "dims": (1, unit_registry.m, 1), |
| 432 | "coords": (1, 1, unit_registry.s), |
| 433 | } |
| 434 | data_unit, dim_unit, coord_unit = variants[variant] |
| 435 | func = functools.partial( |
| 436 | xr.apply_ufunc, np.mean, input_core_dims=[["x"]], kwargs={"axis": -1} |
| 437 | ) |
| 438 | |
| 439 | array1 = np.linspace(0, 10, 5 * 10).reshape(5, 10).astype(dtype) * data_unit |
| 440 | array2 = np.linspace(0, 10, 5).astype(dtype) * data_unit |
| 441 | |
| 442 | x = np.arange(5) * dim_unit |
| 443 | y = np.arange(10) * dim_unit |
| 444 | |
| 445 | u = np.linspace(-1, 1, 10) * coord_unit |
| 446 | |
| 447 | ds = xr.Dataset( |
| 448 | data_vars={"a": (("x", "y"), array1), "b": ("x", array2)}, |
| 449 | coords={"x": x, "y": y, "u": ("y", u)}, |
| 450 | ) |
| 451 | |
| 452 | expected = attach_units(func(strip_units(ds)), extract_units(ds)) |
| 453 | actual = func(ds) |
| 454 | |
| 455 | assert_units_equal(expected, actual) |
| 456 | assert_identical(expected, actual) |
| 457 | |
| 458 | |
| 459 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…