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

Method test_content_manipulation

xarray/tests/test_units.py:3218–3250  ·  view source on GitHub ↗
(self, func, variant, dtype)

Source from the content-addressed store, hash-verified

3216 ids=repr,
3217 )
3218 def test_content_manipulation(self, func, variant, dtype):
3219 unit = unit_registry.m
3220
3221 variants = {
3222 "data": (unit, 1, 1),
3223 "dims": (1, unit, 1),
3224 "coords": (1, 1, unit),
3225 }
3226 data_unit, dim_unit, coord_unit = variants[variant]
3227 quantity = np.linspace(0, 10, 5 * 10).reshape(5, 10).astype(dtype) * data_unit
3228 x = np.arange(quantity.shape[0]) * dim_unit
3229 y = np.arange(quantity.shape[1]) * dim_unit
3230 u = np.linspace(0, 1, quantity.shape[0]) * coord_unit
3231
3232 data_array = xr.DataArray(
3233 name="a",
3234 data=quantity,
3235 coords={"x": x, "u": ("x", u), "y": y},
3236 dims=("x", "y"),
3237 )
3238
3239 stripped_kwargs = {
3240 key: array_strip_units(value) for key, value in func.kwargs.items()
3241 }
3242 units = extract_units(data_array)
3243 units["u"] = getattr(u, "units", None)
3244 units["v"] = getattr(u, "units", None)
3245
3246 expected = attach_units(func(strip_units(data_array), **stripped_kwargs), units)
3247 actual = func(data_array)
3248
3249 assert_units_equal(expected, actual)
3250 assert_identical(expected, actual)
3251
3252 @pytest.mark.parametrize(
3253 "unit",

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected