MCPcopy Index your code
hub / github.com/pydata/xarray / test_apply_ufunc_dataset

Function test_apply_ufunc_dataset

xarray/tests/test_units.py:428–456  ·  view source on GitHub ↗
(variant, dtype)

Source from the content-addressed store, hash-verified

426 ),
427)
428def 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(

Callers

nothing calls this directly

Calls 9

assert_identicalFunction · 0.90
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
extract_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…