bool(Dataset(False)) is True
See original GitHub issueWhat happened:
v=True
bool(xr.DataArray(v)) # True
bool(xr.DataArray(v).to_dataset(name='var')) # True
v=False
bool(xr.DataArray(v)) # False
# unexpected behaviour below
bool(xr.DataArray(v).to_dataset(name='var')) # True
What you expected to happen:
bool(xr.DataArray(False).to_dataset(name='var')) # False
Maybe this is intentional and I dont understand why.
xr.version = ‘0.16.0’
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
true and false operators - treat objects as Boolean values
The false operator returns the bool value true to indicate that its operand is definitely false.
Read more >Boolean values - IBM
A Boolean value represents a truth value; that is, TRUE or FALSE. A Boolean expression or predicate can result in a value of...
Read more >Boolean Data Type
The result of a Boolean expression is either true or false. • Boolean expressions allow us to write programs that decide whether to...
Read more >How come I can add the boolean value False but not True in a ...
I just started investigating the set data type in Python. For some reason, whenever I add the Boolean value of True to a...
Read more >Boolean data type in Python - GeeksforGeeks
Python boolean type is one of the built-in data types provided by Python, which represents one of the two values i.e. True or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We mirror numpy for
DataArray
and, per @keewis ,Mapping
for Dataset. I think we should have a fairly high bar for deviating from those.For those who think
bool(xr.Dataset(dict(x=False)))
should evaluate toFalse
, what do you thinkdict(x=False)
should evaluate to?IIUC, this is somewhat of an edge case — it’s only possible to coerce
DataArray
to bool when there’s exactly one element. (Not that we shouldn’t resolve)👍
If I remember correctly,
Dataset
inherits fromdict
and doesn’t define it’s own__bool__
, so it has the behavior ofdict.__bool__
: