MCPcopy Index your code
hub / github.com/pydata/xarray / test_multi_index_groupby_sum

Function test_multi_index_groupby_sum

xarray/tests/test_groupby.py:137–161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

135
136
137def 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

Callers

nothing calls this directly

Calls 6

stackMethod · 0.95
assert_equalFunction · 0.90
UniqueGrouperClass · 0.90
sumMethod · 0.45
unstackMethod · 0.45
groupbyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…