Skip to content
forked from pydata/xarray

Commit

Permalink
allow passing any iterable to drop when dropping variables (pydata#3693)
Browse files Browse the repository at this point in the history
* allow passing any iterable to drop when dropping variables

* whats-new.rst

* update whats-new.rst
  • Loading branch information
keewis authored Jan 14, 2020
1 parent 4042345 commit e0fd480
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Bug fixes
MultiIndex level names.
- :py:meth:`Dataset.merge` no longer fails when passed a `DataArray` instead of a `Dataset` object.
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Fix a regression in :py:meth:`Dataset.drop`: allow passing any
iterable when dropping variables (:issue:`3552`, :pull:`3693`)
By `Justus Magin <https://github.com/keewis>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
3 changes: 1 addition & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
either_dict_or_kwargs,
hashable,
is_dict_like,
is_list_like,
is_scalar,
maybe_wrap_array,
)
Expand Down Expand Up @@ -3690,7 +3689,7 @@ def drop(self, labels=None, dim=None, *, errors="raise", **labels_kwargs):
raise ValueError("cannot specify dim and dict-like arguments.")
labels = either_dict_or_kwargs(labels, labels_kwargs, "drop")

if dim is None and (is_list_like(labels) or is_scalar(labels)):
if dim is None and (is_scalar(labels) or isinstance(labels, Iterable)):
warnings.warn(
"dropping variables using `drop` will be deprecated; using drop_vars is encouraged.",
PendingDeprecationWarning,
Expand Down
4 changes: 4 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,10 @@ def test_drop_variables(self):
actual = data.drop(["time", "not_found_here"], errors="ignore")
assert_identical(expected, actual)

with pytest.warns(PendingDeprecationWarning):
actual = data.drop({"time", "not_found_here"}, errors="ignore")
assert_identical(expected, actual)

def test_drop_index_labels(self):
data = Dataset({"A": (["x", "y"], np.random.randn(2, 3)), "x": ["a", "b"]})

Expand Down

0 comments on commit e0fd480

Please sign in to comment.