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

Method test_aggregation

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

Source from the content-addressed store, hash-verified

2407 ids=repr,
2408 )
2409 def test_aggregation(self, func, dtype):
2410 array = np.arange(10).astype(dtype) * (
2411 unit_registry.m if func.name != "cumprod" else unit_registry.dimensionless
2412 )
2413 data_array = xr.DataArray(data=array, dims="x")
2414
2415 numpy_kwargs = func.kwargs.copy()
2416 if "dim" in numpy_kwargs:
2417 numpy_kwargs["axis"] = data_array.get_axis_num(numpy_kwargs.pop("dim"))
2418
2419 # units differ based on the applied function, so we need to
2420 # first compute the units
2421 units = extract_units(func(array))
2422 expected = attach_units(func(strip_units(data_array)), units)
2423 actual = func(data_array)
2424
2425 assert_units_equal(expected, actual)
2426 assert_allclose(expected, actual)
2427
2428 @pytest.mark.parametrize(
2429 "func",

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
arangeMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45
copyMethod · 0.45
get_axis_numMethod · 0.45

Tested by

no test coverage detected