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

Method test_aggregation

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

Source from the content-addressed store, hash-verified

1542 ids=repr,
1543 )
1544 def test_aggregation(self, func, dtype):
1545 array = np.linspace(0, 1, 10).astype(dtype) * (
1546 unit_registry.m if func.name != "cumprod" else unit_registry.dimensionless
1547 )
1548 variable = xr.Variable("x", array)
1549
1550 numpy_kwargs = func.kwargs.copy()
1551 if "dim" in func.kwargs:
1552 numpy_kwargs["axis"] = variable.get_axis_num(numpy_kwargs.pop("dim"))
1553
1554 units = extract_units(func(array, **numpy_kwargs))
1555 expected = attach_units(func(strip_units(variable)), units)
1556 actual = func(variable)
1557
1558 assert_units_equal(expected, actual)
1559 assert_allclose(expected, actual)
1560
1561 def test_aggregate_complex(self):
1562 variable = xr.Variable("x", [1, 2j, np.nan] * unit_registry.m)

Callers

nothing calls this directly

Calls 10

assert_allcloseFunction · 0.90
extract_unitsFunction · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45
copyMethod · 0.45
get_axis_numMethod · 0.45

Tested by

no test coverage detected