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

Function test_coarsen_reduce

xarray/tests/test_coarsen.py:163–177  ·  view source on GitHub ↗
(ds: Dataset, window, name)

Source from the content-addressed store, hash-verified

161@pytest.mark.parametrize("window", (1, 2, 3, 4))
162@pytest.mark.parametrize("name", ("sum", "mean", "std", "var", "min", "max", "median"))
163def test_coarsen_reduce(ds: Dataset, window, name) -> None:
164 # Use boundary="trim" to accommodate all window sizes used in tests
165 coarsen_obj = ds.coarsen(time=window, boundary="trim")
166
167 # add nan prefix to numpy methods to get similar behavior as bottleneck
168 actual = coarsen_obj.reduce(getattr(np, f"nan{name}"))
169 expected = getattr(coarsen_obj, name)()
170 assert_allclose(actual, expected)
171
172 # make sure the order of data_var are not changed.
173 assert list(ds.data_vars.keys()) == list(actual.data_vars.keys())
174
175 # Make sure the dimension order is restored
176 for key, src_var in ds.data_vars.items():
177 assert src_var.dims == actual[key].dims
178
179
180@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 5

assert_allcloseFunction · 0.90
keysMethod · 0.80
itemsMethod · 0.80
coarsenMethod · 0.45
reduceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…