()
| 135 | |
| 136 | |
| 137 | def test_multi_index_groupby_sum() -> None: |
| 138 | # regression test for GH873 |
| 139 | ds = xr.Dataset( |
| 140 | {"foo": (("x", "y", "z"), np.ones((3, 4, 2)))}, |
| 141 | {"x": ["a", "b", "c"], "y": [1, 2, 3, 4]}, |
| 142 | ) |
| 143 | expected = ds.sum("z") |
| 144 | actual = ds.stack(space=["x", "y"]).groupby("space").sum("z").unstack("space") |
| 145 | assert_equal(expected, actual) |
| 146 | |
| 147 | with pytest.raises(NotImplementedError): |
| 148 | actual = ( |
| 149 | ds.stack(space=["x", "y"]) |
| 150 | .groupby(space=UniqueGrouper(), z=UniqueGrouper()) |
| 151 | .sum("z") |
| 152 | .unstack("space") |
| 153 | ) |
| 154 | assert_equal(expected, ds) |
| 155 | |
| 156 | if not has_pandas_ge_2_2: |
| 157 | # the next line triggers a mysterious multiindex error on pandas 2.0 |
| 158 | return |
| 159 | |
| 160 | actual = ds.stack(space=["x", "y"]).groupby("space").sum(...).unstack("space") |
| 161 | assert_equal(expected, actual) |
| 162 | |
| 163 | |
| 164 | @requires_pandas_ge_2_2 |
nothing calls this directly
no test coverage detected
searching dependent graphs…