Skip to content

Commit

Permalink
Remove deprecated behavior from dataset.drop docstring (#3451)
Browse files Browse the repository at this point in the history
* remove deprecated behavior from dataset.drop docstring

* remove a few warnings too

* actually keep original form but test for warnings
  • Loading branch information
max-sixty authored and dcherian committed Oct 29, 2019
1 parent 43d07b7 commit 74ca69a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,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 @@ -2117,25 +2117,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

0 comments on commit 74ca69a

Please sign in to comment.