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(rust, python): Address .col(regex).exclude() operations not executing. #10025

Merged
merged 5 commits into from
Jul 26, 2023

Conversation

cmdlineluser
Copy link
Contributor

@cmdlineluser cmdlineluser commented Jul 22, 2023

Fixes #10022

Not sure if this is the optimal way of doing things.

I got rid of the if has_exclude block to let the regex expand and put a call to replace_wildcard_with_column inside expand_regex to remove the exclude nodes.

Current behaviour

import polars as pl

df = pl.DataFrame({'col_1': [1, 2, 3], 'col_2': [2, 4, 3]})

df.select(
    pl.col('^col_.*$').exclude('col_2').mul(10),
    pl.col('^col_.*$').exclude('col_1') / 10
)

# shape: (3, 2)
# ┌───────┬───────┐
# │ col_1 ┆ col_2 │
# │ ---   ┆ ---   │
# │ i64   ┆ i64   │
# ╞═══════╪═══════╡
# │ 1     ┆ 2     │
# │ 2     ┆ 4     │
# │ 3     ┆ 3     │
# └───────┴───────┘

With fix:

df.select(
    pl.col('^col_.*$').exclude('^col_2$').mul(10),
    pl.col('^col_.*$').exclude('col_1') / 10
)

# shape: (3, 2)
# ┌───────┬───────┐
# │ col_1 ┆ col_2 │
# │ ---   ┆ ---   │
# │ i64   ┆ f64   │
# ╞═══════╪═══════╡
# │ 10    ┆ 0.2   │
# │ 20    ┆ 0.4   │
# │ 30    ┆ 0.3   │
# └───────┴───────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jul 22, 2023
@ritchie46
Copy link
Member

Can you add a test for the issue this fixes?

@ritchie46 ritchie46 merged commit f5cd53b into pola-rs:main Jul 26, 2023
23 checks passed
@ritchie46
Copy link
Member

Thank you @cmdlineluser 👍

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.

Operations not working after Expr.exclude
2 participants