Skip to content

GH-50072:[Python] Add tests for replace_with_mask kernel#50102

Open
AnkitAhlawat7742 wants to merge 3 commits into
apache:mainfrom
AnkitAhlawat7742:add_rgulrTest_replacemask_krnl
Open

GH-50072:[Python] Add tests for replace_with_mask kernel#50102
AnkitAhlawat7742 wants to merge 3 commits into
apache:mainfrom
AnkitAhlawat7742:add_rgulrTest_replacemask_krnl

Conversation

@AnkitAhlawat7742
Copy link
Copy Markdown
Contributor

@AnkitAhlawat7742 AnkitAhlawat7742 commented Jun 5, 2026

Fix : #50072

Rationale for this change

The replace_with_mask compute function in PyArrow currently has no Python-level tests for regular use cases.
This PR adds test cases for standard usage of replace_with_mask to ensure the function works correctly.

What changes are included in this PR?

Added parameterized test cases in python/pyarrow/tests/test_compute.py

Are these changes tested?

Yes, Manually

Are there any user-facing changes?

No user-facing changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Python-level unit tests for the pyarrow.compute.replace_with_mask kernel to cover typical usage patterns that previously lacked coverage, as requested in GH-50072.

Changes:

  • Added parameterized tests covering basic replacement behavior across several scalar/array types (ints, strings, floats) including nulls in values and mask.
  • Added coverage for ChunkedArray inputs.
  • Added negative tests for invalid mask length and incorrect replacement counts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/pyarrow/tests/test_compute.py Outdated
Comment thread python/pyarrow/tests/test_compute.py Outdated
Copy link
Copy Markdown
Member

@raulcd raulcd left a comment

Choose a reason for hiding this comment

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

The minor comment from copilot about grammatically incorrect comments makes sense to apply. For the rest looks good to me.
@AlenkaF do you want to take a look?

@github-actions github-actions Bot added awaiting merge Awaiting merge and removed awaiting review Awaiting review labels Jun 5, 2026
Copy link
Copy Markdown
Member

@AlenkaF AlenkaF left a comment

Choose a reason for hiding this comment

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

Thanks for opening up a follow-up PR, much appreciated!

The tests cases are good. I added one nit comment and one connected to the heavy use of parametrization in this PR. I think in all the tests the code is actually less clear due to the bulk of it leaving in the parametrized part. I will not block the PR due to this but feel the tests could be clearer. That would help future maintenance and debugging in the situation when the tests fail.

assert result.to_pylist() == [None]


@pytest.mark.parametrize("arr,mask,replacements,expected", [
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@pytest.mark.parametrize("arr,mask,replacements,expected", [
@pytest.mark.parametrize("arr, mask, replacements, expected", [

Same for others.

# Mask length does not match input array length
(pa.array([1, 2, 3]), pa.array([True, False]), pa.array([10]), None),
])
def test_replace_with_mask_errors(arr, mask, replacements, error_match):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would remove the if branch and the whole parametrization here and do a clean test where array construction and pytest.raises check comes one after the other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Add tests for regular replace_with_mask kernel usage

4 participants