Skip to content

Commit

Permalink
Revert "Deprecate bool(ds) (#6126)" (#6141)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Jan 5, 2022
1 parent e05edea commit 51d4d5f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 16 deletions.
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

0 comments on commit 51d4d5f

Please sign in to comment.