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

Method test_groupby_reductions

xarray/tests/test_groupby.py:1427–1460  ·  view source on GitHub ↗
(
        self, use_flox: bool, method: str, shuffle: bool, chunk: bool
    )

Source from the content-addressed store, hash-verified

1425 )
1426 @pytest.mark.parametrize("method", ["sum", "mean", "median"])
1427 def test_groupby_reductions(
1428 self, use_flox: bool, method: str, shuffle: bool, chunk: bool
1429 ) -> None:
1430 if shuffle and chunk and not has_dask_ge_2024_08_1:
1431 pytest.skip()
1432
1433 array = self.da
1434 if chunk:
1435 array.data = array.chunk({"y": 5}).data
1436 reduction = getattr(np, method)
1437 expected = Dataset(
1438 {
1439 "foo": Variable(
1440 ["x", "abc"],
1441 np.array(
1442 [
1443 reduction(self.x[:, :9], axis=-1),
1444 reduction(self.x[:, 10:], axis=-1),
1445 reduction(self.x[:, 9:10], axis=-1),
1446 ]
1447 ).T,
1448 ),
1449 "abc": Variable(["abc"], np.array(["a", "b", "c"])),
1450 }
1451 )["foo"]
1452
1453 with raise_if_dask_computes():
1454 grouped = array.groupby("abc")
1455 if shuffle:
1456 grouped = grouped.shuffle_to_chunks().groupby("abc")
1457
1458 with xr.set_options(use_flox=use_flox):
1459 actual = getattr(grouped, method)(dim="y")
1460 assert_allclose(expected, actual)
1461
1462 def test_groupby_count(self) -> None:
1463 array = DataArray(

Callers

nothing calls this directly

Calls 7

DatasetClass · 0.90
VariableClass · 0.90
raise_if_dask_computesFunction · 0.90
assert_allcloseFunction · 0.90
chunkMethod · 0.45
groupbyMethod · 0.45
shuffle_to_chunksMethod · 0.45

Tested by

no test coverage detected