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

refactor(python): make structify behaviour experimental, while also extending it to aliased expressions #6615

Merged

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Feb 1, 2023

Closes #6594.

Pending additional consideration (and moving the logic into Rust), auto-structification of multi-output expressions has been...

  • moved behind an experimental Config setting.
  • extended to regular aliased expressions, in addition to kwargs.

Example:

import polars as pl
pl.Config.set_auto_structify(True)

df = pl.DataFrame({
    "x1": [1,4,5],
    "x2": [1,2,3],
}).with_columns(
    pl.col(["x1","x2"]).pct_change().alias("pct_change"),
)

# shape: (3, 3)
# ┌─────┬─────┬─────────────┐
# │ x1  ┆ x2  ┆ pct_change  │
# │ --- ┆ --- ┆ ---         │
# │ i64 ┆ i64 ┆ struct[2]   │
# ╞═════╪═════╪═════════════╡
# │ 1   ┆ 1   ┆ {null,null} │
# │ 4   ┆ 2   ┆ {3.0,1.0}   │
# │ 5   ┆ 3   ┆ {0.25,0.5}  │
# └─────┴─────┴─────────────┘

Update:

Also fixes inconsistent str-to-col behaviour between kwarg / non-kwarg exprs, caused by a missing str_to_lit=False param.

@github-actions github-actions bot added python Related to Python Polars refactor Code improvements that do not change functionality labels Feb 1, 2023
@alexander-beedie alexander-beedie force-pushed the make-structify-experimental branch 2 times, most recently from 32a606a to 9424bd9 Compare February 1, 2023 11:17
…nding it to aliased expressions (not just kwargs)
@ritchie46 ritchie46 merged commit a963e35 into pola-rs:master Feb 2, 2023
@alexander-beedie alexander-beedie deleted the make-structify-experimental branch February 2, 2023 08:38
Vincenthays pushed a commit to Vincenthays/polars that referenced this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Related to Python Polars refactor Code improvements that do not change functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behaviours due to #6497
2 participants