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

Fix replace error when regex has only zero match quantifiers #10760

Merged

Conversation

davidwendt
Copy link
Contributor

Closes #10753

Fixes cudf::strings::replace_re logic that was reading past the end of a string when given a regex that contained net zero match quantifier pattern (e.g. 'D*' or 'D?s?' both can match to nothing).

@davidwendt davidwendt added bug Something isn't working 2 - In Progress Currently a work in progress libcudf Affects libcudf (C++/CUDA) code. strings strings issues (C++ and Python) non-breaking Non-breaking change labels Apr 29, 2022
@davidwendt davidwendt self-assigned this Apr 29, 2022
@davidwendt davidwendt changed the title Bug replace re zero quantifier Fix replace error when regex has only zero match quantifiers Apr 29, 2022
@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #10760 (adaee7b) into branch-22.06 (84f88ce) will increase coverage by 0.02%.
The diff coverage is n/a.

@@               Coverage Diff                @@
##           branch-22.06   #10760      +/-   ##
================================================
+ Coverage         86.40%   86.43%   +0.02%     
================================================
  Files               143      143              
  Lines             22444    22444              
================================================
+ Hits              19393    19399       +6     
+ Misses             3051     3045       -6     
Impacted Files Coverage Δ
python/cudf/cudf/comm/gpuarrow.py 79.76% <ø> (ø)
python/cudf/cudf/core/column/string.py 89.21% <ø> (+0.12%) ⬆️
python/cudf/cudf/core/frame.py 93.41% <ø> (ø)
python/cudf/cudf/core/series.py 95.16% <ø> (ø)
python/custreamz/custreamz/kafka.py 29.16% <ø> (ø)
python/cudf/cudf/_fuzz_testing/utils.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/dataframe.py 93.74% <0.00%> (+0.04%) ⬆️
python/cudf/cudf/core/groupby/groupby.py 91.79% <0.00%> (+0.22%) ⬆️
python/cudf/cudf/core/tools/datetimes.py 84.49% <0.00%> (+0.30%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b8d26f...adaee7b. Read the comment docs.

@davidwendt davidwendt added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currently a work in progress labels Apr 29, 2022
@davidwendt davidwendt marked this pull request as ready for review April 29, 2022 21:02
@davidwendt davidwendt requested a review from a team as a code owner April 29, 2022 21:02
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good. Can we add a test that covers the case that previously failed in #10753?

@bdice
Copy link
Contributor

bdice commented Apr 30, 2022

After reading #10753, I see that the behavior may not be well defined across all regex implementations. This page documents some of those differences: https://www.regular-expressions.info/zerolength.html

However, it seems there is some consensus on how to proceed after a zero-length match:

The simplest solution, which is used by most regex engines, is to start the next match attempt one character after the end of the previous match, if the previous match was zero-length.

I would suggest that we write a test matching this behavior (which is the same as the current behavior, as far as I can tell), and claim that is our "defined" behavior for now. From my understanding, it seems that we have three pieces of evidence that this behavior is reasonable: it matches the user's expectation in #10753, it matches the Python re.sub behavior, and it aligns with the guidance from that webpage on what is "used by most regex engines."

Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test looks great. Thanks @davidwendt! For the record, I checked and the behavior of this test matches that of Python's re.sub. Might be worth adding a Python test for zero-match quantifiers if we already have some tests there.

@github-actions github-actions bot added the Python Affects Python cuDF API. label May 2, 2022
@davidwendt
Copy link
Contributor Author

@gpucibot merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change Python Affects Python cuDF API. strings strings issues (C++ and Python)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] When using libcudf replace_re with ? and *, some combinations of inputs trigger cudaErrorIllegalAddress
4 participants