(use_flox: bool, shuffle: bool)
| 3092 | @pytest.mark.parametrize("use_flox", [True, False]) |
| 3093 | @pytest.mark.parametrize("shuffle", [True, False]) |
| 3094 | def test_multiple_groupers_mixed(use_flox: bool, shuffle: bool) -> None: |
| 3095 | # This groupby has missing groups |
| 3096 | ds = xr.Dataset( |
| 3097 | {"foo": (("x", "y"), np.arange(12).reshape((4, 3)))}, |
| 3098 | coords={"x": [10, 20, 30, 40], "letters": ("x", list("abba"))}, |
| 3099 | ) |
| 3100 | groupers: dict[str, Grouper] = dict( |
| 3101 | x=BinGrouper(bins=[5, 15, 25]), letters=UniqueGrouper() |
| 3102 | ) |
| 3103 | gb = ds.groupby(groupers) |
| 3104 | if shuffle: |
| 3105 | gb = gb.shuffle_to_chunks().groupby(groupers) |
| 3106 | expected_data = np.array( |
| 3107 | [ |
| 3108 | [[0.0, np.nan], [np.nan, 3.0]], |
| 3109 | [[1.0, np.nan], [np.nan, 4.0]], |
| 3110 | [[2.0, np.nan], [np.nan, 5.0]], |
| 3111 | ] |
| 3112 | ) |
| 3113 | expected = xr.Dataset( |
| 3114 | {"foo": (("y", "x_bins", "letters"), expected_data)}, |
| 3115 | coords={ |
| 3116 | "x_bins": ( |
| 3117 | "x_bins", |
| 3118 | pd.IntervalIndex.from_breaks([5, 15, 25], closed="right"), |
| 3119 | ), |
| 3120 | "letters": ("letters", np.array(["a", "b"], dtype=object)), |
| 3121 | }, |
| 3122 | ) |
| 3123 | with xr.set_options(use_flox=use_flox): |
| 3124 | actual = gb.sum() |
| 3125 | assert_identical(actual, expected) |
| 3126 | |
| 3127 | # assert_identical( |
| 3128 | # b.groupby(['x', 'y']).apply(lambda x: x - x.mean()), |
| 3129 | # b - b.mean("z"), |
| 3130 | # ) |
| 3131 | |
| 3132 | # gb = square.groupby(x=UniqueGrouper(), y=UniqueGrouper()) |
| 3133 | # gb - gb.mean() |
| 3134 | |
| 3135 | # ------ |
| 3136 | |
| 3137 | |
| 3138 | @requires_flox_0_9_12 |
nothing calls this directly
no test coverage detected
searching dependent graphs…