Skip to content

Commit

Permalink
DeprecationWarning -> FutureWarning
Browse files Browse the repository at this point in the history
The `DeprecationWarning` is ignored by default for `.assign_coords` due
to the
stacklevel (pydata#6798 (comment))

Use `FutureWarning` instead to show the warning for both `.assign` and
`.assign_coords`.
  • Loading branch information
benbovy committed Sep 28, 2022
1 parent 914a1a1 commit ee9b027
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion xarray/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,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:
Expand Down
4 changes: 1 addition & 3 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4136,14 +4136,10 @@ 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)
Expand Down

0 comments on commit ee9b027

Please sign in to comment.