Skip to content

Commit fed8520

Browse files
authored
fix dataset groupby combine dataarray func (#6386)
Dataset._overwrite_indexes and DataArray._overwrite_indexes have different parameter names (for consistency with other internals).
1 parent 03b6ba1 commit fed8520

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

xarray/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ def _combine(self, applied):
996996
if coord is not None and dim not in applied_example.dims:
997997
index, index_vars = create_default_index_implicit(coord)
998998
indexes = {k: index for k in index_vars}
999-
combined = combined._overwrite_indexes(indexes, variables=index_vars)
999+
combined = combined._overwrite_indexes(indexes, index_vars)
10001000
combined = self._maybe_restore_empty_groups(combined)
10011001
combined = self._maybe_unstack(combined)
10021002
return combined

xarray/tests/test_groupby.py

+8
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,14 @@ def test_groupby_dataset_assign():
934934
assert_identical(actual, expected)
935935

936936

937+
def test_groupby_dataset_map_dataarray_func():
938+
# regression GH6379
939+
ds = xr.Dataset({"foo": ("x", [1, 2, 3, 4])}, coords={"x": [0, 0, 1, 1]})
940+
actual = ds.groupby("x").map(lambda grp: grp.foo.mean())
941+
expected = xr.DataArray([1.5, 3.5], coords={"x": [0, 1]}, dims="x", name="foo")
942+
assert_identical(actual, expected)
943+
944+
937945
class TestDataArrayGroupBy:
938946
@pytest.fixture(autouse=True)
939947
def setup(self):

0 commit comments

Comments
 (0)