-
Notifications
You must be signed in to change notification settings - Fork 144
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
'Cause PEP-8 never goes out of style #558
Conversation
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.
For builtin Python booleans, testing == False
and is False
have the same behavior, but for other types this is not the case. In particular for numpy
arrays, these do entirely different things: is
compares the identity of the array object itself, while ==
is an elementwise value comparison. For example:
In [1]: import numpy as np
In [2]: ar = np.random.rand(3,3)
In [3]: ar
Out[3]:
array([[0.12607551, 0.56005212, 0.42254926],
[0.48698435, 0.5986023 , 0.75294198],
[0.82027795, 0.58230241, 0.92049683]])
In [4]: b = ar > 0.5
In [5]: b
Out[5]:
array([[False, True, False],
[False, True, True],
[ True, True, True]])
In [6]: b is False
Out[6]: False
In [7]: b == False
Out[7]:
array([[ True, False, True],
[ True, False, False],
[False, False, False]])
There is also one place where I can't tell the original meaning of the code, but from context it looks like it should actually be an assignment (=
) rather than an equality test (see review comment).
Thanks @sezelt |
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.
Thanks for the changes. I think we are just waiting on clarification of that one line whose original meaning was unclear
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.
Just needs clarification on the line in fit.py
So this is just changing every boolean |
From PEP-8:
See also this Stackoverflow: This thread actually shows an interesting example where a numpy function that returns a scalar boolean does not return a Python singleton, and thus would behave differently under this change. |
It changes
@sezelt caught the examples I incorrectly changed, which were used in numpy masks. |
@sezelt @bsavitzky Changed to assignment should be good to go |
pep 8 - Comparisons to singletons compliance