Skip to content
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

E712 fix silently breaks Pandas/Polars queries #9883

Closed
david-waterworth opened this issue Feb 7, 2024 · 3 comments
Closed

E712 fix silently breaks Pandas/Polars queries #9883

david-waterworth opened this issue Feb 7, 2024 · 3 comments

Comments

@david-waterworth
Copy link

david-waterworth commented Feb 7, 2024

The following fragments

df.filter(pl.col("X")==True) # polars
df[df["X"]==True] # pandas

are flagged as E712 violations, however the fix is invalid, and worse it silently changes the result of the query, causing subtle and hard to find errors.

df.filter(pl.col("X") is True) # polars
df[df["X"] is True] # pandas

The correct fix is

df.filter(pl.col("X")) # polars
df[df["X"]] # pandas

and for completeness, ==False should be replaced by

df.filter(~pl.col("X")) # polars
df[~df["X"]] # pandas
@charliermarsh
Copy link
Member

I believe this fix is marked as unsafe for this reason. Did you opt-in to the fix with --unsafe-fixes, or do you have unsafe-fixes = true enabled in your project? If so, I think Ruff's behavior here is okay... I'd love to make sure we don't flag these at all, but at least it's not a silent breakage, and instead one that's surfaced to the user as potentially-unsafe.

(I'm going to merge this ticket into #4560 which tracks the underlying limitation.)

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
@david-waterworth
Copy link
Author

@charliermarsh I think what I probably did is manually apply the fix in vscode (i.e. right click on the squiggle generated by the ruff vscode extensions) as I defn don't have --unsafe-fixes set.

So I guess the issue here is the extension might have displayed safe and unsafe fixes in the same colour (i.e. yellow underline) or perhaps I just didn't read the message correctly. Either way that issue should be raise in the ruff vscode extension repo so I'll double check and raise it there.

@charliermarsh
Copy link
Member

Ahh yeah this makes total sense. I think we have an issue for that in the VS Code extension repo: astral-sh/ruff-vscode#342.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants