-
Notifications
You must be signed in to change notification settings - Fork 122
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: concat_str
#1128
Merged
Merged
feat: concat_str
#1128
Conversation
This file contains 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
Fixed via the following change: + series = (s.astype(str) for _expr in parsed_exprs for s in _expr._call(df))
- series = (s for _expr in parsed_exprs for s in _expr.cast(self._dtypes.String()._call(df)) |
MarcoGorelli
approved these changes
Oct 6, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice one @FBruzzesi, great use of pl.fold
!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
high priority
Your PR will be reviewed very quickly if you address this
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.
What type of PR is this? (check all applicable)
Related issues
nw.concat_str
to horizontally concatenate string columnsΒ #1116Checklist
If you have comments or can explain your changes, please do so below.
This was a bit harder/more complex than expected to get right. The idea being that polars can switch between:
ignore_nulls=False
(default), which means that a single null in the row will be propagated to the final result.ignore_nulls=True
, when this happens, it is not as simple as replacing the null with an empty string, since otherwise the separator will get repeated (I am using a reduce). Also the separator "attached" to the same column and row needs to be nullified to empty string.All this comes out of the box with polars>=0.20.6 and pyarrow (not sure about min version, CI will tell). On the other hand for pandas, dask and polars<0.20.6, a fair bit of manipulation had to be done, especially for
ignore_nulls=True
.The gist of it is using a null_mask, a list of series corresponding to the null values of the original series, and use it to map both the null values and the separators to an empty string.
It has also been a long day, so maybe tomorrow I can take another look with some fresh eyes