(
self, use_flox: bool, method: str, shuffle: bool, chunk: bool
)
| 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( |
nothing calls this directly
no test coverage detected