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

feat(python): rework pl.exclude as a pure selector, allowing other selectors as input #13301

Merged
merged 2 commits into from Dec 30, 2023

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Dec 28, 2023

Closes #13247.

  • Implemented pl.exclude as a dedicated selector (it now redirects to the new cs.exclude); adds flexibility, combining all input names/dtypes/selectors into a single/compound selector expression before subtracting that from cs.all().
  • Adds expr.meta.is_column(), as it's useful to know if an expression is a simple column or not; this allows for some parsing simplifications/extensions here, and a follow-up PR taking additional advantage is coming shortly.

Note

We can consider retiring pl.exclude in the future as it is now a pure redirect to the more capable cs.exclude.

Example

import polars.selectors as cs
import polars as pl

df = pl.DataFrame({"a": [1], "b": [2], "c": [3]})

df.with_columns(
    pl.exclude(cs.first(), cs.last()) + 100
)
# shape: (1, 3)
# ┌─────┬─────┬─────┐
# │ a   ┆ b   ┆ c   │
# │ --- ┆ --- ┆ --- │
# │ i64 ┆ i64 ┆ i64 │
# ╞═════╪═════╪═════╡
# │ 1   ┆ 102 ┆ 3   │
# └─────┴─────┴─────┘

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Dec 28, 2023
@alexander-beedie alexander-beedie changed the title feat(python): rework pl.exclude as a pure selector, allowing selectors to be given as input feat(python): rework pl.exclude as a pure selector, allowing other selectors as input Dec 28, 2023
@ritchie46 ritchie46 merged commit ec8c9e0 into pola-rs:main Dec 30, 2023
32 checks passed
@alexander-beedie alexander-beedie deleted the pl-exclude-selectors branch December 30, 2023 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support expressions and selectors in exclude
2 participants