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!: Native selector XOR set operation, guarantee consistent selector column-order #16833

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jun 9, 2024

Closes #16822:

  • Adds a proper selector xor implementation (inc. .meta, and Python operator integration), with associated docs/tests.

...and some bonus updates/fixes.

  • Makes the contains selector signature consistent with the related starts_with and ends_with selectors (eg: can now write the cleaner cs.contains("a","b","c") instead of cs.contains(("a","b","c"))).
  • Fixes an issue raised in the Discord with inconsistently ordered selector results - selector set operations should always return matching columns in schema order, irrespective of which selector is on the lhs/rhs of the op.

(The update to contains is breaking if anyone is calling "cs.contains(substring='xyz')" instead of "cs.contains('xyz')". Arguably so is ensuring consistent column return order, though I consider that a fix rather than a breaking change ;)

Example

import polars as pl

df = pl.DataFrame(
    schema={
        "col1": pl.String,
        "col2": pl.Boolean,
        "col3": pl.String,
        "col4": pl.Boolean,
    },
)

df.select(cs.boolean() ^ cs.ends_with("1","2"))
# shape: (0, 2)
# ┌──────┬──────┐
# │ col1 ┆ col4 │
# │ ---  ┆ ---  │
# │ str  ┆ bool │
# ╞══════╪══════╡
# └──────┴──────┘

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Jun 9, 2024
@alexander-beedie alexander-beedie changed the title feat: Native selector XOR set operation, and guarantee consistent selector column-order feat!: Native selector XOR set operation, and guarantee consistent selector column-order Jun 9, 2024
@github-actions github-actions bot added the breaking Change that breaks backwards compatibility label Jun 9, 2024
@alexander-beedie alexander-beedie added the A-selectors Area: column selectors label Jun 9, 2024
Copy link

codecov bot commented Jun 9, 2024

Codecov Report

Attention: Patch coverage is 89.61039% with 8 lines in your changes missing coverage. Please review.

Project coverage is 81.36%. Comparing base (d9fe109) to head (675cca5).
Report is 1 commits behind head on main.

Files Patch % Lines
py-polars/polars/selectors.py 61.53% 4 Missing and 1 partial ⚠️
crates/polars-plan/src/dsl/meta.rs 83.33% 2 Missing ⚠️
...plan/src/logical_plan/conversion/expr_expansion.rs 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16833      +/-   ##
==========================================
- Coverage   81.38%   81.36%   -0.02%     
==========================================
  Files        1425     1425              
  Lines      187612   187652      +40     
  Branches     2697     2700       +3     
==========================================
+ Hits       152680   152686       +6     
- Misses      34437    34470      +33     
- Partials      495      496       +1     

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

@alexander-beedie alexander-beedie force-pushed the selector-xor-and-ordering branch from bb6a11c to 675cca5 Compare June 9, 2024 13:01
@alexander-beedie alexander-beedie changed the title feat!: Native selector XOR set operation, and guarantee consistent selector column-order feat!: Native selector XOR set operation, guarantee consistent selector column-order Jun 9, 2024
@ritchie46 ritchie46 merged commit e56d748 into pola-rs:main Jun 10, 2024
29 checks passed
@alexander-beedie alexander-beedie deleted the selector-xor-and-ordering branch June 10, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-selectors Area: column selectors breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add inline XOR (^) operator for selectors
2 participants