MCPcopy
hub / github.com/pydata/xarray / test_resample

Method test_resample

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

Source from the content-addressed store, hash-verified

5393 ),
5394 )
5395 def test_resample(self, variant, dtype):
5396 # TODO: move this to test_computation_objects
5397 variants = {
5398 "data": ((unit_registry.degK, unit_registry.Pa), 1, 1),
5399 "dims": ((1, 1), unit_registry.m, 1),
5400 "coords": ((1, 1), 1, unit_registry.m),
5401 }
5402 (unit1, unit2), dim_unit, coord_unit = variants[variant]
5403
5404 array1 = np.linspace(-5, 5, 10 * 5).reshape(10, 5).astype(dtype) * unit1
5405 array2 = np.linspace(10, 20, 10 * 8).reshape(10, 8).astype(dtype) * unit2
5406
5407 t = xr.date_range("10-09-2010", periods=array1.shape[0], freq="YE")
5408 y = np.arange(5) * dim_unit
5409 z = np.arange(8) * dim_unit
5410
5411 u = np.linspace(-1, 0, 5) * coord_unit
5412
5413 ds = xr.Dataset(
5414 data_vars={"a": (("time", "y"), array1), "b": (("time", "z"), array2)},
5415 coords={"time": t, "y": y, "z": z, "u": ("y", u)},
5416 )
5417 units = extract_units(ds)
5418
5419 func = method("resample", time="6ME")
5420
5421 expected = attach_units(func(strip_units(ds)).mean(), units)
5422 actual = func(ds).mean()
5423
5424 assert_units_equal(expected, actual)
5425 assert_equal(expected, actual)
5426
5427 @pytest.mark.parametrize("compute_backend", ["numbagg", None], indirect=True)
5428 @pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 11

assert_equalFunction · 0.90
extract_unitsFunction · 0.85
methodClass · 0.85
attach_unitsFunction · 0.85
strip_unitsFunction · 0.85
assert_units_equalFunction · 0.85
linspaceMethod · 0.80
arangeMethod · 0.80
funcFunction · 0.70
astypeMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected