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

Allow expressions for date_range parameters #5231

Closed
datenzauberai opened this issue Oct 17, 2022 · 2 comments · Fixed by #5267
Closed

Allow expressions for date_range parameters #5231

datenzauberai opened this issue Oct 17, 2022 · 2 comments · Fixed by #5267
Assignees
Labels
enhancement New feature or an improvement of an existing feature

Comments

@datenzauberai
Copy link
Contributor

datenzauberai commented Oct 17, 2022

Problem description

Currently date_range does not accept expressions. This means that we always have to use apply when calculating various date ranges for different rows/groups.

We could speed up typical data wrangling operations like filling missing dates with this enhancement. Example:

def complete_missing(df, by, time_column, every):
    return (df
        .groupby(by)
        .agg(
            pl.struct([pl.col(time_column).min().alias("_start"), pl.col(time_column).max().alias("_end")])
            .apply(lambda row: pl.date_range(row["_start"], row["_end"], interval=every)).alias(time_column)
        )
        .explode(time_column)
        .join(df, how="left", on=by + [time_column])
    )
@datenzauberai datenzauberai added the enhancement New feature or an improvement of an existing feature label Oct 17, 2022
@datenzauberai
Copy link
Contributor Author

datenzauberai commented Oct 17, 2022

See also #5159

@ritchie46
Copy link
Member

I have setup a PR for that in #5267.

Now I am stuck on the @overload types, so any help with that would be great.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants