Repository: pydata/xarray

Issue:
Dataset.drop() no longer works with a set as an argument
#### MCVE Code Sample
<!-- In order for the maintainers to efficiently understand and prioritize issues, we ask you post a "Minimal, Complete and Verifiable Example" (MCVE): http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports -->

```python
# Your code here
#!/usr/bin/env python

import xarray
import numpy

ds = xarray.Dataset()
ds['x'] = ('x', numpy.linspace(0., 1., 100))
ds['y'] = ('y', numpy.linspace(0., 1., 50))
print(ds)
ds = ds.drop(set('x'))
print(ds)
```

#### Expected Output
```
<xarray.Dataset>
Dimensions:  (x: 100, y: 50)
Coordinates:
  * x        (x) float64 0.0 0.0101 0.0202 0.0303 ... 0.9697 0.9798 0.9899 1.0
  * y        (y) float64 0.0 0.02041 0.04082 0.06122 ... 0.9592 0.9796 1.0
Data variables:
    *empty*
<xarray.Dataset>
Dimensions:  (y: 50)
Coordinates:
  * y        (y) float64 0.0 0.02041 0.04082 0.06122 ... 0.9592 0.9796 1.0
Data variables:
    *empty*
```

#### Problem Description
<!-- this should explain why the current behavior is a problem and why the expected output is a better solution -->

In versions before xarray 0.14.1, the code above involving calls to `Dataset.drop()` with a `set` as an argument worked as expected.  With the new release, the result is an error as shown below.  This is breaking backwards compatibility with our software ([MPAS-Analysis](https://github.com/MPAS-Dev/MPAS-Analysis)).

```
<xarray.Dataset>
Dimensions:  (x: 100, y: 50)
Coordinates:
  * x        (x) float64 0.0 0.0101 0.0202 0.0303 ... 0.9697 0.9798 0.9899 1.0
  * y        (y) float64 0.0 0.02041 0.04082 0.06122 ... 0.9592 0.9796 1.0
Data variables:
    *empty*
Traceback (most recent call last):
  File "./drop_issue.py", line 10, in <module>
    ds = ds.drop(set('x'))
  File "/home/xylar/miniconda3/envs/test/lib/python3.7/site-packages/xarray/core/dataset.py", line 3643, in drop
    return self.drop_sel(labels, errors=errors)
  File "/home/xylar/miniconda3/envs/test/lib/python3.7/site-packages/xarray/core/dataset.py", line 3689, in drop_sel
    labels = either_dict_or_kwargs(labels, labels_kwargs, "drop")
  File "/home/xylar/miniconda3/envs/test/lib/python3.7/site-packages/xarray/core/utils.py", line 257, in either_dict_or_kwargs
    "the first argument to .%s must be a dictionary" % func_name
ValueError: the first argument to .drop must be a dictionary
```

#### Output of ``xr.show_versions()``
<details>
# Paste the output here xr.show_versions() here
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21) 
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 4.15.0-1063-oem
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.1

xarray: 0.14.1
pandas: 0.25.3
numpy: 1.17.3
scipy: 1.3.2
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.1
dask: 2.8.0
distributed: 2.8.0
matplotlib: 3.1.2
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 41.6.0.post20191101
pip: 19.3.1
conda: None
pytest: 5.3.0
IPython: None
sphinx: None
</details>


Discussion:
dcherian: Great. Thanks @keewis 

Patch:
diff --git a/doc/whats-new.rst b/doc/whats-new.rst
index 6eeb55c2..1ad344a2 100644
--- a/doc/whats-new.rst
+++ b/doc/whats-new.rst
@@ -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
 ~~~~~~~~~~~~~
diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py
index 1aaad02b..79f1030f 100644
--- a/xarray/core/dataset.py
+++ b/xarray/core/dataset.py
@@ -85,7 +85,6 @@ from .utils import (
     either_dict_or_kwargs,
     hashable,
     is_dict_like,
-    is_list_like,
     is_scalar,
     maybe_wrap_array,
 )
@@ -3690,7 +3689,7 @@ class Dataset(Mapping, ImplementsDatasetReduce, DataWithCoords):
                 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,


Test patch:
diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py
index c953f5d2..f9eb37db 100644
--- a/xarray/tests/test_dataset.py
+++ b/xarray/tests/test_dataset.py
@@ -2167,6 +2167,10 @@ class TestDataset:
             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"]})