Skip to content
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

Finish deprecation cycle for DataArray.__contains__ checking array values #2520

Merged
merged 1 commit into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ v0.11.0 (unreleased)
Breaking changes
~~~~~~~~~~~~~~~~

- ``Dataset.T`` has been removed as a shortcut for :py:meth:`Dataset.transpose`.
Call :py:meth:`Dataset.transpose` directly instead.
- Iterating over a ``Dataset`` now includes only data variables, not coordinates.
Similarily, calling ``len`` and ``bool`` on a ``Dataset`` now
includes only data variables
- Finished deprecation cycles:
- ``Dataset.T`` has been removed as a shortcut for :py:meth:`Dataset.transpose`.
Call :py:meth:`Dataset.transpose` directly instead.
- Iterating over a ``Dataset`` now includes only data variables, not coordinates.
Similarily, calling ``len`` and ``bool`` on a ``Dataset`` now
includes only data variables.
- ``DataArray.__contains__`` (used by Python's ``in`` operator) now checks
array data, not coordinates.
- 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
Expand Down
6 changes: 1 addition & 5 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,7 @@ def _item_sources(self):
LevelCoordinatesSource(self)]

def __contains__(self, key):
warnings.warn(
'xarray.DataArray.__contains__ currently checks membership in '
'DataArray.coords, but in xarray v0.11 will change to check '
'membership in array values.', FutureWarning, stacklevel=2)
return key in self._coords
return key in self.data

@property
def loc(self):
Expand Down
7 changes: 4 additions & 3 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ def get_data():
da[dict(x=ind)] = value # should not raise

def test_contains(self):
data_array = DataArray(1, coords={'x': 2})
with pytest.warns(FutureWarning):
assert 'x' in data_array
data_array = DataArray([1, 2])
assert 1 in data_array
assert 3 not in data_array

def test_attr_sources_multiindex(self):
# make sure attr-style access for multi-index levels
Expand Down Expand Up @@ -2533,6 +2533,7 @@ def test_upsample_interpolate_regression_1605(self):
assert_allclose(actual, expected, rtol=1e-16)

@requires_dask
@requires_scipy
def test_upsample_interpolate_dask(self):
import dask.array as da

Expand Down