Skip to content

allow passing any iterable to drop when dropping variables #3693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 14, 2020
Merged
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
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
@@ -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
~~~~~~~~~~~~~
3 changes: 1 addition & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
@@ -85,7 +85,6 @@
either_dict_or_kwargs,
hashable,
is_dict_like,
is_list_like,
is_scalar,
maybe_wrap_array,
)
@@ -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,
4 changes: 4 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -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"]})