-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[ruff --fix] (v0.0.239) When working with numpy arrays mask == True
is not the same as mask is True
#2443
Comments
Ah yeah, this has come up before. Unfortunately it's really hard to avoid without disabling the rule entirely, though I'm open to suggestions on heuristics. My current suggestion has been to disable that rule if you're working in any context that requires boolean comparisons like that. |
This could potentially also happen with sqlalchemy I guess. |
Can you point me out in the direction where this code lives? It looks like
On the other hand at least in our case we have many people coming from the c-embedded world and writing python in a c-ish way and in general I find it also helpful. |
Verified today this is the case. |
Potentially something that could be defined as a E.g. a Not sure if it would make more sense to do the analysis at the AST level though, and check for |
We could consider ignoring these expressions inside of all |
I think this would wind up chasing a lot of stragglers. E.g. |
Maybe this should wait until we can determine the type of objects. |
To share another real world example, I encountered this using ruff in a project that uses SQLAlchemy. Ruff fixed comparisons with Our usage seems harder to detect as a special case since we construct the list of filters outside of the call. It only seems feasible to avoid by detecting the type of the object in the comparison. |
Wonder if those operators were influenced by the recent language/tooling co-design. I seem to remember having issues with the |
#1852 has some previous discussion as well. @charliermarsh if you'd like I can open a new issue that tracks the general problem replacing |
Could be labeled |
Here's the aforementioned tracking issue #4560 |
Thanks tons @madkinsz |
After running
ruff --fix
the last line of the following script gets reformatted asnp.where(mask is True)
but in this context is not the same.Maybe in that context one should not be using
np.where(mask == True)
but it's equivalentmask.nonzero()
instead, at anyrate we have some old code using that pattern.See below an interactive session showing is not the same.
What do you think about this corner case?
The text was updated successfully, but these errors were encountered: