diff --git a/xarray/core/coordinates.py b/xarray/core/coordinates.py index 42cc8130810..47350b9403f 100644 --- a/xarray/core/coordinates.py +++ b/xarray/core/coordinates.py @@ -315,6 +315,7 @@ def _maybe_drop_multiindex_coords(self, coords: set[Hashable]) -> None: variables, indexes = drop_coords( coords, self._data._variables, self._data.xindexes ) + self._data._coord_names.intersection_update(variables) self._data._variables = variables self._data._indexes = indexes @@ -441,7 +442,7 @@ def drop_coords( f"other variables: {list(maybe_midx.index.names)!r}. " f"This will raise an error in the future. Use `.drop_vars({idx_coord_names!r})` before " "assigning new coordinate values.", - DeprecationWarning, + FutureWarning, stacklevel=4, ) for k in idx_coord_names: diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 3602b87102d..bdbf2deac12 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -1501,9 +1501,7 @@ def test_assign_coords(self) -> None: def test_assign_coords_existing_multiindex(self) -> None: data = self.mda - with pytest.warns( - DeprecationWarning, match=r"Updating MultiIndexed coordinate" - ): + with pytest.warns(FutureWarning, match=r"Updating MultiIndexed coordinate"): data.assign_coords(x=range(4)) def test_coords_alignment(self) -> None: diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index bc6410a6d4a..07ac491a10c 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -4136,16 +4136,16 @@ def test_assign_multiindex_level(self) -> None: def test_assign_coords_existing_multiindex(self) -> None: data = create_test_multiindex() - with pytest.warns( - DeprecationWarning, match=r"Updating MultiIndexed coordinate" - ): + with pytest.warns(FutureWarning, match=r"Updating MultiIndexed coordinate"): data.assign_coords(x=range(4)) - with pytest.warns( - DeprecationWarning, match=r"Updating MultiIndexed coordinate" - ): + with pytest.warns(FutureWarning, match=r"Updating MultiIndexed coordinate"): data.assign(x=range(4)) + # https://github.com/pydata/xarray/issues/7097 (coord names updated) + updated = data.assign_coords(x=range(4)) + assert len(updated.coords) == 1 + def test_assign_all_multiindex_coords(self) -> None: data = create_test_multiindex() actual = data.assign(x=range(4), level_1=range(4), level_2=range(4))