Skip to content

Add additional regex pytests derived from cudf-spark integration tests - #23065

Merged
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
davidwendt:spark-regex-tests
Jul 1, 2026
Merged

Add additional regex pytests derived from cudf-spark integration tests#23065
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
davidwendt:spark-regex-tests

Conversation

@davidwendt

Copy link
Copy Markdown
Contributor

Description

Adds an additional set of regex pytests based on the cudf-spark test suite.
This is split out from the work in #21936 since it is the only python change there.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@davidwendt davidwendt self-assigned this Jul 1, 2026
@davidwendt
davidwendt requested a review from a team as a code owner July 1, 2026 14:49
@davidwendt
davidwendt requested a review from wence- July 1, 2026 14:49
@davidwendt davidwendt added the 3 - Ready for Review Ready for review by team label Jul 1, 2026
@davidwendt
davidwendt requested a review from galipremsagar July 1, 2026 14:49
@davidwendt davidwendt added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jul 1, 2026
@github-actions github-actions Bot added Python Affects Python cuDF API. pylibcudf Issues specific to the pylibcudf package labels Jul 1, 2026
@GPUtester GPUtester moved this to In Progress in cuDF Python Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved test coverage for string regex matching and replacement across a wider range of inputs, including empty strings, whitespace, control characters, and null values.
    • Added coverage for common regex patterns such as quantifiers, alternation, anchors, character classes, and backreferences, helping ensure more consistent results in string operations.

Walkthrough

This PR expands regex test coverage in two pylibcudf test modules (test_string_contains.py, test_string_replace_re.py) by adding a shared _make_prog helper, a spark_strings fixture, and numerous parametrized tests derived from cudf-spark integration tests, covering quantifiers, alternation, character classes, and ASCII-semantics edge cases for contains_re and replace_re.

Changes

Spark regex test coverage

Layer / File(s) Summary
contains_re helper and parametrization
python/pylibcudf/tests/test_string_contains.py
Adds _make_prog(pattern) helper and rewrites test_contains_re to parametrize over multiple inputs and patterns.
contains_re Spark fixture and pattern coverage
python/pylibcudf/tests/test_string_contains.py
Adds spark_strings fixture and many new parametrized tests for quantifiers, alternation, anchors, repetition, groups, character classes, and a hardcoded \W ASCII-semantics case.
replace_re helper and backreference update
python/pylibcudf/tests/test_string_replace_re.py
Adds _make_prog(pattern) helper and updates existing tests to use it.
replace_re Spark fixture and pattern coverage
python/pylibcudf/tests/test_string_replace_re.py
Adds spark_strings fixture, REPLACE_REPL constant, and new parametrized tests for basic patterns, negated/digit/word classes, alternations, and non-capturing groups.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • rapidsai/cudf#22639: Related to replace_re API testing changes around the RegexProgram-driven single-pattern API.
  • rapidsai/cudf#22874: Expands regex-behavior coverage for the same contains_re/replace_re APIs with overlapping semantics.
  • rapidsai/cudf#22994: The new _make_prog helpers rely on RegexProgram construction from regex flags, aligning with underlying reprog::create_from flag threading.

Suggested reviewers: vyasr, bdice

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding regex pytest coverage derived from cudf-spark integration tests.
Description check ✅ Passed The description is clearly related to the changeset and correctly states that additional regex pytests were added from cudf-spark tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
python/pylibcudf/tests/test_string_spark_regex.py (1)

70-227: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting a shared assertion helper to reduce duplication.

Nearly every test_contains_re_* and test_replace_re_* function repeats the identical 4-line pattern of building got, computing expect via pyarrow, and calling assert_column_eq. Extracting a small helper (e.g., _assert_contains_matches(strings, pattern) / _assert_replace_matches(strings, pattern, repl)) would reduce duplication across ~13 test functions and make future changes (e.g., swapping the comparison library) a one-line edit.

♻️ Example helper extraction
+def _assert_contains_matches(strings, pattern):
+    got = plc.strings.contains.contains_re(
+        plc.Column.from_arrow(strings),
+        _make_prog(pattern),
+    )
+    expect = pc.match_substring_regex(strings, pattern)
+    assert_column_eq(expect, got)
+
+
 def test_contains_re_basic(spark_strings, pattern):
-    got = plc.strings.contains.contains_re(
-        plc.Column.from_arrow(spark_strings),
-        _make_prog(pattern),
-    )
-    expect = pc.match_substring_regex(spark_strings, pattern)
-    assert_column_eq(expect, got)
+    _assert_contains_matches(spark_strings, pattern)

Also applies to: 243-380

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/pylibcudf/tests/test_string_spark_regex.py` around lines 70 - 227, The
test functions repeat the same build/compare/assert flow, so extract shared
assertion helpers to reduce duplication. Add a small helper around the repeated
pattern in test_contains_re_* (and the related test_replace_re_* group mentioned
in the review) that takes the input column/pattern and performs the
got/expect/assert_column_eq steps. Update the existing tests to call the helper,
using the existing symbols _make_prog, plc.strings.contains.contains_re,
pc.match_substring_regex, and assert_column_eq so the behavior stays unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@python/pylibcudf/tests/test_string_spark_regex.py`:
- Around line 70-227: The test functions repeat the same build/compare/assert
flow, so extract shared assertion helpers to reduce duplication. Add a small
helper around the repeated pattern in test_contains_re_* (and the related
test_replace_re_* group mentioned in the review) that takes the input
column/pattern and performs the got/expect/assert_column_eq steps. Update the
existing tests to call the helper, using the existing symbols _make_prog,
plc.strings.contains.contains_re, pc.match_substring_regex, and assert_column_eq
so the behavior stays unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8b2131e8-b868-4cbe-9a6c-347ab70e76a3

📥 Commits

Reviewing files that changed from the base of the PR and between 11af57b and d36ec1e.

📒 Files selected for processing (1)
  • python/pylibcudf/tests/test_string_spark_regex.py

Comment thread python/pylibcudf/tests/test_string_spark_regex.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
python/pylibcudf/tests/test_string_contains.py (1)

114-249: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider consolidating the repeated test bodies.

test_contains_re_basic, _alternation, _anchors_wildcards, _bounded_repetition, _groups, _char_classes, and _escape_edge_cases all share an identical 5-line body, differing only in the parametrize pattern list. Could combine into a single parametrized test (or a shared helper function called by each) while keeping the category comments for documentation purposes.

♻️ Example consolidation
+def _assert_contains_re(spark_strings, pattern):
+    got = plc.strings.contains.contains_re(
+        plc.Column.from_arrow(spark_strings),
+        _make_prog(pattern),
+    )
+    expect = pc.match_substring_regex(spark_strings, pattern)
+    assert_column_eq(expect, got)
+
+
 # Basic quantifiers (test_rlike, test_regexp, test_regexp_like)
 `@pytest.mark.parametrize`(
     "pattern",
     [
         "a{2}",
         "a{1,3}",
         "a{1,}",
         "a[bc]d",
     ],
 )
 def test_contains_re_basic(spark_strings, pattern):
-    got = plc.strings.contains.contains_re(
-        plc.Column.from_arrow(spark_strings),
-        _make_prog(pattern),
-    )
-    expect = pc.match_substring_regex(spark_strings, pattern)
-    assert_column_eq(expect, got)
+    _assert_contains_re(spark_strings, pattern)

Also applies to: 263-280

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/pylibcudf/tests/test_string_contains.py` around lines 114 - 249,
Consolidate the duplicated regex assertion logic across test_contains_re_basic,
test_contains_re_alternation, test_contains_re_anchors_wildcards,
test_contains_re_bounded_repetition, test_contains_re_groups, and
test_contains_re_char_classes by moving the shared
contains_re/pc.match_substring_regex/assert_column_eq body into one parametrized
test or a small helper. Keep the existing category comments for readability, but
avoid repeating the same setup and assertion block in each test function; use
the unique test names and _make_prog to preserve current behavior.
python/pylibcudf/tests/test_string_replace_re.py (1)

53-89: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate spark_strings fixture across test modules.

This fixture is identical to the one in test_string_contains.py (Lines 75-109 per provided context). Consider hoisting it into a shared conftest.py fixture to avoid maintaining two copies in sync.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@python/pylibcudf/tests/test_string_replace_re.py` around lines 53 - 89, The
spark_strings fixture is duplicated in multiple test modules, so move the shared
array fixture into a common conftest.py and remove the local copy from
test_string_replace_re.py. Keep the fixture name spark_strings so existing tests
continue to use it without changes, and update any imports or module-level
references if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@python/pylibcudf/tests/test_string_contains.py`:
- Around line 114-249: Consolidate the duplicated regex assertion logic across
test_contains_re_basic, test_contains_re_alternation,
test_contains_re_anchors_wildcards, test_contains_re_bounded_repetition,
test_contains_re_groups, and test_contains_re_char_classes by moving the shared
contains_re/pc.match_substring_regex/assert_column_eq body into one parametrized
test or a small helper. Keep the existing category comments for readability, but
avoid repeating the same setup and assertion block in each test function; use
the unique test names and _make_prog to preserve current behavior.

In `@python/pylibcudf/tests/test_string_replace_re.py`:
- Around line 53-89: The spark_strings fixture is duplicated in multiple test
modules, so move the shared array fixture into a common conftest.py and remove
the local copy from test_string_replace_re.py. Keep the fixture name
spark_strings so existing tests continue to use it without changes, and update
any imports or module-level references if needed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 24b4b88b-b586-42a5-8be9-b2faf275b9fc

📥 Commits

Reviewing files that changed from the base of the PR and between d36ec1e and fcfdeef.

📒 Files selected for processing (2)
  • python/pylibcudf/tests/test_string_contains.py
  • python/pylibcudf/tests/test_string_replace_re.py

@mroeschke

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot
rapids-bot Bot merged commit 21c0840 into NVIDIA:main Jul 1, 2026
130 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in cuDF Python Jul 1, 2026
@davidwendt
davidwendt deleted the spark-regex-tests branch July 1, 2026 21:44
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 improvement Improvement / enhancement to an existing function non-breaking Non-breaking change pylibcudf Issues specific to the pylibcudf package Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants