-
Notifications
You must be signed in to change notification settings - Fork 989
Support cudf-polars str.zfill
#19081
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
Merged
rapids-bot
merged 21 commits into
rapidsai:branch-25.10
from
brandon-b-miller:fea-cudf-polars-str-zfill
Aug 5, 2025
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3c0ce28
impl, tests, some failing
brandon-b-miller ae87f78
error cases, edge case, still one edge case to go
brandon-b-miller d120908
Merge branch 'branch-25.08' into fea-cudf-polars-str-zfill
brandon-b-miller 285c108
dont hardcode typestr
brandon-b-miller b4b7e74
excize pyarrow
brandon-b-miller da8fb55
merge/resolve
brandon-b-miller 7e0051c
Merge branch 'branch-25.08' into fea-cudf-polars-str-zfill
brandon-b-miller ed9f3e1
tests, impl
brandon-b-miller 66c9ec9
scan
brandon-b-miller 6069e72
xfail
brandon-b-miller c6f0465
merge/fixup
brandon-b-miller 6c25f14
Merge branch 'branch-25.08' into fea-cudf-polars-str-zfill
brandon-b-miller aea2c62
Merge branch 'branch-25.08' into fea-cudf-polars-str-zfill
brandon-b-miller ab8f5d9
Update python/cudf_polars/cudf_polars/dsl/expressions/string.py
brandon-b-miller a555822
add expected failure
brandon-b-miller 7d9fba6
move scalar validation to query planning phase
brandon-b-miller 2bdbcc9
Merge branch 'branch-25.08' into fea-cudf-polars-str-zfill
mroeschke 0fdb116
Merge branch 'branch-25.08' into fea-cudf-polars-str-zfill
brandon-b-miller 25479ef
merge/resolve
brandon-b-miller af96c67
add validation, refactor
brandon-b-miller 3cbc55e
conditional xfail
brandon-b-miller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -504,6 +504,106 @@ def test_string_join(ldf, ignore_nulls, delimiter): | |||||||||
| assert_gpu_result_equal(q) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @pytest.mark.parametrize( | ||||||||||
| "fill", | ||||||||||
| [ | ||||||||||
| 0, | ||||||||||
| 1, | ||||||||||
| 2, | ||||||||||
| 5, | ||||||||||
| 999, | ||||||||||
| -1, | ||||||||||
| None, | ||||||||||
| ], | ||||||||||
| ) | ||||||||||
| @pytest.mark.parametrize( | ||||||||||
| "input_strings", | ||||||||||
| [ | ||||||||||
| ["1", "0"], | ||||||||||
| ["123", "45"], | ||||||||||
| ["", "0"], | ||||||||||
| ["abc", "def"], | ||||||||||
| ], | ||||||||||
| ) | ||||||||||
| def test_string_zfill(fill, input_strings): | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you run these tests with polars 1.29? You might need to version guard these tests ie |
||||||||||
| ldf = pl.LazyFrame({"a": input_strings}) | ||||||||||
| q = ldf.select(pl.col("a").str.zfill(fill)) | ||||||||||
|
|
||||||||||
| if fill is not None and fill < 0: | ||||||||||
| assert_collect_raises( | ||||||||||
| q, | ||||||||||
| polars_except=pl.exceptions.InvalidOperationError, | ||||||||||
| cudf_except=pl.exceptions.ComputeError, | ||||||||||
| ) | ||||||||||
| else: | ||||||||||
| assert_gpu_result_equal(q) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @pytest.mark.parametrize( | ||||||||||
| "fill", | ||||||||||
| [ | ||||||||||
| 5 | ||||||||||
| if not POLARS_VERSION_LT_130 | ||||||||||
| else pytest.param(5, marks=pytest.mark.xfail(reason="fixed in Polars 1.30")), | ||||||||||
|
Comment on lines
+545
to
+547
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(For a follow up PR if interested) |
||||||||||
| 999 | ||||||||||
| if not POLARS_VERSION_LT_130 | ||||||||||
| else pytest.param(999, marks=pytest.mark.xfail(reason="fixed in Polars 1.30")), | ||||||||||
| ], | ||||||||||
| ) | ||||||||||
| def test_string_zfill_pl_129(fill): | ||||||||||
| ldf = pl.LazyFrame({"a": ["-1", "+2"]}) | ||||||||||
| q = ldf.select(pl.col("a").str.zfill(fill)) | ||||||||||
| assert_gpu_result_equal(q) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @pytest.mark.parametrize( | ||||||||||
| "fill", | ||||||||||
| [ | ||||||||||
| 0, | ||||||||||
| 1, | ||||||||||
| 2, | ||||||||||
| 5 | ||||||||||
| if not POLARS_VERSION_LT_130 | ||||||||||
| else pytest.param(5, marks=pytest.mark.xfail(reason="fixed in Polars 1.30")), | ||||||||||
| 999 | ||||||||||
| if not POLARS_VERSION_LT_130 | ||||||||||
| else pytest.param(999, marks=pytest.mark.xfail(reason="fixed in Polars 1.30")), | ||||||||||
| -1, | ||||||||||
| pytest.param(None, marks=pytest.mark.xfail(reason="None dtype")), | ||||||||||
| ], | ||||||||||
| ) | ||||||||||
| def test_string_zfill_column(fill): | ||||||||||
| ldf = pl.DataFrame( | ||||||||||
| { | ||||||||||
| "input_strings": ["1", "0", "123", "45", "", "0", "-1", "+2", "abc", "def"], | ||||||||||
| "fill": [fill] * 10, | ||||||||||
| } | ||||||||||
| ).lazy() | ||||||||||
| q = ldf.select(pl.col("input_strings").str.zfill(pl.col("fill"))) | ||||||||||
| if fill is not None and fill < 0: | ||||||||||
| assert_collect_raises( | ||||||||||
| q, | ||||||||||
| polars_except=pl.exceptions.InvalidOperationError, | ||||||||||
| cudf_except=pl.exceptions.InvalidOperationError | ||||||||||
| if not POLARS_VERSION_LT_130 | ||||||||||
| else pl.exceptions.ComputeError, | ||||||||||
| ) | ||||||||||
| else: | ||||||||||
| assert_gpu_result_equal(q) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_string_zfill_forbidden_chars(): | ||||||||||
| ldf = pl.LazyFrame({"a": ["Café", "345", "東京", None]}) | ||||||||||
| q = ldf.select(pl.col("a").str.zfill(3)) | ||||||||||
| assert_collect_raises( | ||||||||||
| q, | ||||||||||
| polars_except=(), | ||||||||||
| cudf_except=pl.exceptions.InvalidOperationError | ||||||||||
| if not POLARS_VERSION_LT_130 | ||||||||||
| else pl.exceptions.ComputeError, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| @pytest.mark.parametrize( | ||||||||||
| "width", | ||||||||||
| [ | ||||||||||
|
|
||||||||||
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.
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.
should we do this introspection?
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.
cc @mroeschke , do we usually introspect data to error at this point? If we don't, then we risk maybe producing the wrong result in some edge cases, like a negative
fillvalue in the zfill column overload. The scalar case is easy enough to introspect and throw, but this is a whole scan.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.
Is this a case where we wouldn't be able to match the result (not necessarily an error) that Polars produces?
If so, yes, I think there's some precedent on introspecting the data to raise an error. We would want to do this in
_validate_inputthough so it can raise during translation. Plus we can do this introspection on the CPU by doing a similar option on Polars objectsThere 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.
The case this intends to match is the one where one of the fill elements in the column overload is negative, polars throws at runtime in this case. I suppose we want to match that behavior, but it's a performance hit to every call to the column overload :(