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

Revert "Deprecate bool(ds) (#6126)" #6141

Merged
merged 1 commit into from
Jan 5, 2022
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
5 changes: 0 additions & 5 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ Deprecations
By `Tom Nicholas <https://github.com/TomNicholas>`_.


- Coercing a dataset to bool, e.g. ``bool(ds)``, is being deprecated and will raise an
error in a future version (not yet planned). For now, invoking ``Dataset.__bool__``
issues a ``PendingDeprecationWarning`` (:issue:`6124`, :pull:`6126`).
By `Michael Delgado <https://github.com/delgadom>`_.

Bug fixes
~~~~~~~~~
- Properly support :py:meth:`DataArray.ffill`, :py:meth:`DataArray.bfill`, :py:meth:`Dataset.ffill` and :py:meth:`Dataset.bfill` along chunked dimensions (:issue:`6112`).
Expand Down
8 changes: 0 additions & 8 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,14 +1456,6 @@ def __len__(self) -> int:
return len(self.data_vars)

def __bool__(self) -> bool:
warnings.warn(
"coercing a Dataset to a bool will be deprecated. "
"Using bool(ds.data_vars) to check for at least one "
"data variable or using Dataset.to_array to test "
"whether array values are true is encouraged.",
PendingDeprecationWarning,
stacklevel=2,
)
return bool(self.data_vars)

def __iter__(self) -> Iterator[Hashable]:
Expand Down
4 changes: 1 addition & 3 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,7 @@ def test_properties(self):
assert "aasldfjalskdfj" not in ds.variables
assert "dim1" in repr(ds.variables)
assert len(ds) == 3

with pytest.warns(PendingDeprecationWarning):
assert bool(ds)
assert bool(ds)

assert list(ds.data_vars) == ["var1", "var2", "var3"]
assert list(ds.data_vars.keys()) == ["var1", "var2", "var3"]
Expand Down