(variant, dtype)
| 393 | ), |
| 394 | ) |
| 395 | def test_apply_ufunc_dataarray(variant, dtype): |
| 396 | variants = { |
| 397 | "data": (unit_registry.m, 1, 1), |
| 398 | "dims": (1, unit_registry.m, 1), |
| 399 | "coords": (1, 1, unit_registry.m), |
| 400 | } |
| 401 | data_unit, dim_unit, coord_unit = variants[variant] |
| 402 | func = functools.partial( |
| 403 | xr.apply_ufunc, np.mean, input_core_dims=[["x"]], kwargs={"axis": -1} |
| 404 | ) |
| 405 | |
| 406 | array = np.linspace(0, 10, 20).astype(dtype) * data_unit |
| 407 | x = np.arange(20) * dim_unit |
| 408 | u = np.linspace(-1, 1, 20) * coord_unit |
| 409 | data_array = xr.DataArray(data=array, dims="x", coords={"x": x, "u": ("x", u)}) |
| 410 | |
| 411 | expected = attach_units(func(strip_units(data_array)), extract_units(data_array)) |
| 412 | actual = func(data_array) |
| 413 | |
| 414 | assert_units_equal(expected, actual) |
| 415 | assert_identical(expected, actual) |
| 416 | |
| 417 | |
| 418 | @pytest.mark.parametrize( |
nothing calls this directly
no test coverage detected
searching dependent graphs…