diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 6512d48d7d8..af7a7982df5 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -33,6 +33,9 @@ v0.11.0 (unreleased) Breaking changes ~~~~~~~~~~~~~~~~ +- Iterating over a ``Dataset`` now includes only data variables, not coordinates. + Similarily, calling ``len`` and ``bool`` on a ``Dataset`` now + includes only data variables - Xarray's storage backends now automatically open and close files when necessary, rather than requiring opening a file with ``autoclose=True``. A global least-recently-used cache is used to store open files; the default diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 756cd795540..534029b9aff 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -930,32 +930,13 @@ def __contains__(self, key): return key in self._variables def __len__(self): - warnings.warn('calling len() on an xarray.Dataset will change in ' - 'xarray v0.11 to only include data variables, not ' - 'coordinates. Call len() on the Dataset.variables ' - 'property instead, like ``len(ds.variables)``, to ' - 'preserve existing behavior in a forwards compatible ' - 'manner.', - FutureWarning, stacklevel=2) - return len(self._variables) + return len(self.data_vars) def __bool__(self): - warnings.warn('casting an xarray.Dataset to a boolean will change in ' - 'xarray v0.11 to only include data variables, not ' - 'coordinates. Cast the Dataset.variables property ' - 'instead to preserve existing behavior in a forwards ' - 'compatible manner.', - FutureWarning, stacklevel=2) - return bool(self._variables) + return bool(self.data_vars) def __iter__(self): - warnings.warn('iteration over an xarray.Dataset will change in xarray ' - 'v0.11 to only include data variables, not coordinates. ' - 'Iterate over the Dataset.variables property instead to ' - 'preserve existing behavior in a forwards compatible ' - 'manner.', - FutureWarning, stacklevel=2) - return iter(self._variables) + return iter(self.data_vars) def __array__(self, dtype=None): raise TypeError('cannot directly convert an xarray.Dataset into a ' diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 89704653e92..adc809662f8 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -420,16 +420,12 @@ def test_properties(self): assert isinstance(ds.dims.mapping, utils.SortedKeysDict) assert type(ds.dims.mapping.mapping) is dict # noqa - with pytest.warns(FutureWarning): - assert list(ds) == list(ds.variables) - with pytest.warns(FutureWarning): - assert list(ds.keys()) == list(ds.variables) + assert list(ds) == list(ds.data_vars) + assert list(ds.keys()) == list(ds.data_vars) assert 'aasldfjalskdfj' not in ds.variables assert 'dim1' in repr(ds.variables) - with pytest.warns(FutureWarning): - assert len(ds) == 7 - with pytest.warns(FutureWarning): - assert bool(ds) + assert len(ds) == 3 + assert bool(ds) assert list(ds.data_vars) == ['var1', 'var2', 'var3'] assert list(ds.data_vars.keys()) == ['var1', 'var2', 'var3']