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

fix: Invalid selectors not being recognized #19136

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pavelzw
Copy link

@pavelzw pavelzw commented Oct 8, 2024

Closes #19023

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Oct 8, 2024
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.51%. Comparing base (1f48036) to head (3947452).
Report is 43 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19136      +/-   ##
==========================================
- Coverage   79.78%   79.51%   -0.28%     
==========================================
  Files        1531     1527       -4     
  Lines      208427   209204     +777     
  Branches     2913     2415     -498     
==========================================
+ Hits       166295   166345      +50     
- Misses      41581    42311     +730     
+ Partials      551      548       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pavelzw pavelzw marked this pull request as ready for review October 8, 2024 10:42
def test_invalid_selector() -> None:
df = pl.DataFrame(data={"x": [1, 2], "z": ["a", "b"]})
with pytest.raises(InvalidOperationError, match="invalid selector expression"):
df.drop(pl.col("x", "z") + 2) # type: ignore[arg-type]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whys does mypy complain here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❯ mypy py-polars/tests/unit/test_selectors.py
py-polars/tests/unit/test_selectors.py:822: error: Argument 1 to "drop" of "DataFrame" has incompatible type "Expr"; expected "str | _selector_proxy_ | Iterable[str | _selector_proxy_]"  [arg-type]
py-polars/tests/unit/test_selectors.py:824: error: Argument 1 to "drop" of "DataFrame" has incompatible type "Expr"; expected "str | _selector_proxy_ | Iterable[str | _selector_proxy_]"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think we must pass a seelctor as we don't allow expression inputs here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could reproduce the issue as well with the following:

pl.selectors.all() + pl.col("x")

which is at runtime a _selector_proxy_, mypy still thinks it's a Expr, hence the assert in 3947452 (#19136)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No exception raised when doing Selector + list in DataFrame.drop.
2 participants