Repository navigation
Plain values in grouped expressions are not broadcast since Polars 0.52 - #1169
Open
jotaviobiondo wants to merge 1 commit into
Open
jotaviobiondo wants to merge 1 commit into
jotaviobiondo wants to merge 1 commit into
Conversation
Explorer passes plain values in expressions, such as the branches of `if` or the `1` in `sum(a) + 1`, as series literals of size 1. Up to Polars 0.49, a literal of length 1 was taken as a scalar and broadcast to every group. With Polars 0.55, only scalar literals are broadcast. A series literal expands to its own values in every group, so on grouped dataframes `mutate/2` raises on mismatched lengths and `summarise/2` returns lists. Series literals of size 1 are now lowered as scalar literals.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explorer passes plain values in expressions to Polars as one-item series. Examples are the branches of
if, the1insum(a) + 1, and the fallback ofcoalesce. Up to Polars 0.49, Polars took any literal of length 1 as a scalar. Since Polars 0.52 (Explorer v0.12.0), only scalar literals are broadcast over groups. A series literal expands to its own values in each group. On grouped dataframes this means:mutate/2raiseslengths don't matchsummarise/2returns lists instead of one value per groupFix
Explorer.PolarsBackend.Expressionnow sends a series of size 1 to Polars as a scalar literal. This applies both to a lazyfrom_listof one value and to an eager series of size 1. The literal is cast to the series dtype when that differs from the inferred dtype. Values that the NIF has no scalar literal for (such asDecimalandTime) are sent aslit(series).first(), which Polars also takes as one value per group. There are no changes on the Rust side.Reproduction
Before (v0.13.0):
After (this branch):
This PR was done with the help of AI. I'm not fully sure if there is a better solution here, but seemed the right path. I wanted to at least report the problem problem together with a possible solution.