diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 3c26c2129ae..9212549d4ad 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -996,7 +996,7 @@ def _combine(self, applied): if coord is not None and dim not in applied_example.dims: index, index_vars = create_default_index_implicit(coord) indexes = {k: index for k in index_vars} - combined = combined._overwrite_indexes(indexes, variables=index_vars) + combined = combined._overwrite_indexes(indexes, index_vars) combined = self._maybe_restore_empty_groups(combined) combined = self._maybe_unstack(combined) return combined diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index f866b68dfa8..327c8d34b18 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -934,6 +934,14 @@ def test_groupby_dataset_assign(): assert_identical(actual, expected) +def test_groupby_dataset_map_dataarray_func(): + # regression GH6379 + ds = xr.Dataset({"foo": ("x", [1, 2, 3, 4])}, coords={"x": [0, 0, 1, 1]}) + actual = ds.groupby("x").map(lambda grp: grp.foo.mean()) + expected = xr.DataArray([1.5, 3.5], coords={"x": [0, 1]}, dims="x", name="foo") + assert_identical(actual, expected) + + class TestDataArrayGroupBy: @pytest.fixture(autouse=True) def setup(self):