(
method: Literal["cumsum", "cumprod"],
grp_idx: list[str],
dim,
expected_array: list[float],
use_flox: bool,
use_dask: bool,
use_lazy_group_idx: bool,
)
| 2632 | ], |
| 2633 | ) |
| 2634 | def test_groupby_scans( |
| 2635 | method: Literal["cumsum", "cumprod"], |
| 2636 | grp_idx: list[str], |
| 2637 | dim, |
| 2638 | expected_array: list[float], |
| 2639 | use_flox: bool, |
| 2640 | use_dask: bool, |
| 2641 | use_lazy_group_idx: bool, |
| 2642 | ) -> None: |
| 2643 | if use_dask and not has_dask: |
| 2644 | pytest.skip("requires dask") |
| 2645 | |
| 2646 | if use_flox: |
| 2647 | if not has_flox: |
| 2648 | pytest.skip("requires flox") |
| 2649 | |
| 2650 | if method == "cumprod": |
| 2651 | pytest.skip( |
| 2652 | "TODO: Groupby with cumprod is currently not supported with flox" |
| 2653 | ) |
| 2654 | if dim == ...: |
| 2655 | pytest.skip( |
| 2656 | "TODO: Scans are only supported along a single dimension in flox." |
| 2657 | ) |
| 2658 | elif dim == "test": |
| 2659 | pytest.skip( |
| 2660 | "TODO: group_idx along time dim and axis along test dim not currently supported with flox." |
| 2661 | ) |
| 2662 | elif use_lazy_group_idx: |
| 2663 | pytest.skip("Lazy group_idx is not supported without flox.") |
| 2664 | |
| 2665 | # Test Dataset groupby: |
| 2666 | ds = xr.Dataset( |
| 2667 | { |
| 2668 | "foo": ( |
| 2669 | ("test", "time"), |
| 2670 | [[7, 2, 0, 1, 2, np.nan], [1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2]], |
| 2671 | ) |
| 2672 | }, |
| 2673 | coords={ |
| 2674 | "time": [0, 1 / 6, 2 / 6, 3 / 6, 4 / 6, 5 / 6], |
| 2675 | "test": ["a", "b", "b"], |
| 2676 | "group_idx": ("time", [0, 0, 1, 1, 2, 2]), |
| 2677 | "group_idx2": ("time", [0, 1, 1, 1, 1, 1]), |
| 2678 | }, |
| 2679 | ) |
| 2680 | |
| 2681 | with xr.set_options(use_flox=use_flox): |
| 2682 | if use_dask: |
| 2683 | ds = ds.chunk() |
| 2684 | if use_lazy_group_idx and module_available("flox", minversion="0.10.5"): |
| 2685 | # This path requires flox installed. |
| 2686 | gs = { |
| 2687 | g: xr.groupers.UniqueGrouper(labels=np.unique(ds[g])) |
| 2688 | for g in grp_idx |
| 2689 | } |
| 2690 | actual = getattr(ds.groupby(gs), method)(dim) |
| 2691 | else: |
nothing calls this directly
no test coverage detected
searching dependent graphs…