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
Support __bool__
where sensible
#2695
Conversation
if (self.unit() != scipp::units::none) | ||
throw scipp::except::UnitError( | ||
"The thruth value of a variable with unit is undefined."); | ||
return self.template value<bool>() == true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the part that makes sure we don't have more than one value in the self
? self.value
raises if the variable is not 0-D?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct.
|
||
|
||
def test_scalar_Variable_conversion_to_builtin_bool_bad_dtype(): | ||
var = sc.scalar(value=1.0, unit=None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, do we support conversion from integer? e.g. sc.scalar(value=1, unit=None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because we use .value<bool>()
.
Co-authored-by: Neil Vaytet <39047984+nvaytet@users.noreply.github.com>
if (self.unit() != scipp::units::none) | ||
throw scipp::except::UnitError( | ||
"The thruth value of a variable with unit is undefined."); | ||
return self.template value<bool>() == true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing check for variances?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool
cannot have variances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right
Fixes #2691.