diff --git a/xarray/core/alignment.py b/xarray/core/alignment.py index d201e3a613f..1bdbf9c890e 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -927,8 +927,8 @@ def _get_broadcast_dims_map_common_coords(args, exclude): for dim in arg.dims: if dim not in common_coords and dim not in exclude: dims_map[dim] = arg.sizes[dim] - if dim in arg.coords: - common_coords[dim] = arg.coords[dim].variable + if dim in arg.xindexes: + common_coords.update(arg.xindexes[dim].create_variables()) return dims_map, common_coords diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 25adda2df84..f5ed5e763a9 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -2331,6 +2331,18 @@ def test_broadcast_misaligned(self): assert_identical(expected_x2, x2) assert_identical(expected_y2, y2) + def test_broadcast_multi_index(self): + # GH6430 + ds = Dataset( + {"foo": (("x", "y", "z"), np.ones((3, 4, 2)))}, + {"x": ["a", "b", "c"], "y": [1, 2, 3, 4]}, + ) + stacked = ds.stack(space=["x", "y"]) + broadcasted, _ = broadcast(stacked, stacked.space) + + assert broadcasted.xindexes["x"] is broadcasted.xindexes["space"] + assert broadcasted.xindexes["y"] is broadcasted.xindexes["space"] + def test_variable_indexing(self): data = create_test_data() v = data["var1"]