Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3536,7 +3536,6 @@ def drop( # noqa: F811
----------
labels : hashable or iterable of hashables
Name(s) of variables or index labels to drop.
If dim is not None, labels can be any array-like.
dim : None or hashable, optional
Dimension along which to drop index labels. By default (if
``dim is None``), drops variables rather than index labels.
Expand Down
18 changes: 12 additions & 6 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2118,25 +2118,31 @@ def test_drop_variables(self):
def test_drop_index_labels(self):
data = Dataset({"A": (["x", "y"], np.random.randn(2, 3)), "x": ["a", "b"]})

actual = data.drop(["a"], "x")
with pytest.warns(DeprecationWarning):
actual = data.drop(["a"], "x")
expected = data.isel(x=[1])
assert_identical(expected, actual)

actual = data.drop(["a", "b"], "x")
with pytest.warns(DeprecationWarning):
actual = data.drop(["a", "b"], "x")
expected = data.isel(x=slice(0, 0))
assert_identical(expected, actual)

with pytest.raises(KeyError):
# not contained in axis
data.drop(["c"], dim="x")
with pytest.warns(DeprecationWarning):
data.drop(["c"], dim="x")

actual = data.drop(["c"], dim="x", errors="ignore")
with pytest.warns(DeprecationWarning):
actual = data.drop(["c"], dim="x", errors="ignore")
assert_identical(data, actual)

with pytest.raises(ValueError):
data.drop(["c"], dim="x", errors="wrong_value")
with pytest.warns(DeprecationWarning):
data.drop(["c"], dim="x", errors="wrong_value")

actual = data.drop(["a", "b", "c"], "x", errors="ignore")
with pytest.warns(DeprecationWarning):
actual = data.drop(["a", "b", "c"], "x", errors="ignore")
expected = data.isel(x=slice(0, 0))
assert_identical(expected, actual)

Expand Down