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(python): Add dtype argument for repeat #8946

Merged
merged 4 commits into from
May 21, 2023

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented May 20, 2023

Closes #8771

Not sure this is the right way to go, since we're now casting after the repeat call. But then again, this is also how Series.repeat was already implemented, and also similar to lit(dtype=...).

In the issue, @ritchie46 you mentioned to "cast the anyvalue before you expand", but I'm not sure how that would work.

I also made repeat(name=...) work for expressions; no reason it shouldn't.

As a side note, I don't see the point of the n argument supporting Expr input - it creates the expectation that the following will somehow work, but it doesn't:

df = pl.DataFrame({'n': [1, 2, 3]})
df.select(pl.repeat(5, n=pl.col('n')))

Results in:

shape: (1, 1)
┌─────────┐
│ literal │
│ ---     │
│ i32     │
╞═════════╡
│ 5       │
└─────────┘

Apparently only the very first value of the expression is considered? This is unexpected.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels May 20, 2023
@stinodego stinodego marked this pull request as draft May 21, 2023 14:52
@stinodego stinodego marked this pull request as ready for review May 21, 2023 15:56
@stinodego
Copy link
Member Author

I will merge this, but I'll follow up with some more related improvements/refactor.

@stinodego stinodego merged commit 042367a into pola-rs:main May 21, 2023
9 checks passed
c-peters pushed a commit to c-peters/polars that referenced this pull request Jul 14, 2023
@stinodego stinodego deleted the repeat-dtype branch December 8, 2023 15:48
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repeat should support a dtype argument
2 participants