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

Function test_apply_ufunc_dataarray

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

Source from the content-addressed store, hash-verified

393 ),
394)
395def 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(

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…