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(rust, python): deprecate 'use_earliest' argument in favour of 'ambiguous', which can take expressions #10719

Merged
merged 3 commits into from
Aug 26, 2023

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Aug 24, 2023

closes #10090 (note: if it's OK, I'll work on adding the new options suggested in that issue in separate PRs, this one's already quite large)

Before: when-then-otherwise gymnastics

df = pl.DataFrame(
    {
        "ts": [datetime(2020, 10, 25, 1), datetime(2020, 10, 25, 1)],
        "use_earliest": [True, False],
    }
)
df.with_columns(
    ts_london=pl.when(pl.col("use_earliest"))
    .then(pl.col("ts").dt.replace_time_zone("Europe/London", use_earliest=True))
    .otherwise(
        pl.col("ts").dt.replace_time_zone("Europe/London", use_earliest=False)
    )
)

After: just pass an expression

df = pl.DataFrame(
    {
        "ts": [datetime(2020, 10, 25, 1), datetime(2020, 10, 25, 1)],
        "ambiguous": ["earliest", "latest"],
    }
)
df.with_columns(
    ts_london=pl.col("ts").dt.replace_time_zone(
        "Europe/London", ambiguous=pl.col("ambiguous")
    )
)

Similarly for .dt.truncate, .dt.to_datetime, and pl.datetime

@MarcoGorelli MarcoGorelli changed the title WIP feat(rust, python): deprecate 'use_earliest' argument in favour of 'ambiguous', which can take expressions feat(rust, python): deprecate 'use_earliest' argument in favour of 'ambiguous', which can take expressions Aug 25, 2023
@MarcoGorelli MarcoGorelli marked this pull request as ready for review August 25, 2023 13:17
@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 Aug 25, 2023
Copy link
Member

@ritchie46 ritchie46 left a comment

Choose a reason for hiding this comment

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

Looks good to me! 👍

@ritchie46 ritchie46 merged commit 3e84f29 into pola-rs:main Aug 26, 2023
27 checks passed
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 rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use_earliest might be mis-designed
2 participants