`numpy.bool_(True) is True` evaluates to `False`
See original GitHub issueEven though numpy.bool_(True) == True
evaluates to True
. Doesn’t this violate the PEP8 recommendation that ``Comparisons to singletons like None should always be done with is or is not, never the equality operators.`?
Sorry, if this is a dupe. I searched for bool comarison and pep8 and could not find an relevant issue.
numpy.__version__
: 1.9.0.dev-297f54b
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Why do "Not a Number" values equal True when cast as ...
1. My hunch: NaN is not equal to zero, so it's true when converted to boolean. If NaN were false, then conversion of...
Read more >Python and numpy Bool Types
~False in fact evaluates to True. If you want to correctly negate Python boolean values use logical not and not bitwise not (...
Read more >Python Booleans: Optimize Your Code With Truth Values
You can think of True and False as Boolean operators that take no inputs. One of these operators always returns True , and...
Read more >Python Booleans - W3Schools
Booleans represent one of two values: True or False . Boolean Values. In programming you often need to know if an expression is...
Read more >Logic functions — NumPy v1.24 Manual
Test whether all array elements along a given axis evaluate to True. ... Test element-wise for NaN and return result as a boolean...
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 FreeTop 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
Top GitHub Comments
Actually, the PEP8 recommendation for
True
andFalse
is that you don’t compare them against anything, not with==
, and especially not withis
, but use them directly. The following is the relevant paragraph:The pep recommendation doesn’t mean that nothing is allowed to compare == to singletons, just that if you’re checking for the literal singleton True object you should use “is” to do that. And np.bool_(True) is a different object than True – it has to be, it’s a different class! – so “is” will return False no matter what pep 8 says.
See also: 1 == True, 1 is True On Jun 5, 2015 12:53 AM, “Ludwig Schmidt-Hackenberg” < notifications@github.com> wrote: