handle dynamic pattern columns in str.replace and str.replace_all#26874
Closed
moktamd wants to merge 2 commits intopola-rs:mainfrom
Closed
handle dynamic pattern columns in str.replace and str.replace_all#26874moktamd wants to merge 2 commits intopola-rs:mainfrom
moktamd wants to merge 2 commits intopola-rs:mainfrom
Conversation
when both pattern and value are column expressions rather than scalars, the replace functions panicked with "dynamic pattern length not supported". this happened regularly with POLARS_MAX_THREADS=1 because single-threaded execution preserves multi-chunk column layouts that get rechunked in the multi-threaded path. added element-wise iteration over pattern, value, and source columns for the (len_pat, len_val) match arm in both replace_n and replace_all, compiling the regex per-row.
Contributor
Author
|
Oh, missed that one. Closing in favor of #26807. |
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.
Fixes #26789
When both pattern and value are column expressions (not scalar),
str.replaceandstr.replace_allpanic withdynamic pattern length in 'str.replace' expressions is not supported yet. Reproduces consistently withPOLARS_MAX_THREADS=1because single-threaded execution preserves multi-chunk layouts that the multi-threaded path rechunks into a single chunk.The
(1, len_val)arm handles scalar pattern + dynamic values, but there was no arm for(len_pat, len_val)where both are dynamic. Added element-wise iteration over source, pattern, and value columns for bothreplace_nandreplace_all, compiling regex per-row via the existing cache.Added
test_replace_dynamic_pattern_columncovering literal replacement, replace vs replace_all with repeated matches, regex patterns from columns, and a single-row regression guard.