-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-5854: [Python] Expose compare kernels on Array class #7273
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
Closed
jorisvandenbossche
wants to merge
2
commits into
apache:master
from
jorisvandenbossche:ARROW-5854-array-compare
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -238,3 +238,78 @@ def test_filter_errors(): | |
| with pytest.raises(pa.ArrowInvalid, | ||
| match="must all be the same length"): | ||
| obj.filter(mask) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("typ", ["array", "chunked_array"]) | ||
| def test_compare_array(typ): | ||
| if typ == "array": | ||
| def con(values): return pa.array(values) | ||
| else: | ||
| def con(values): return pa.chunked_array([values]) | ||
|
|
||
| arr1 = con([1, 2, 3, 4, None]) | ||
| arr2 = con([1, 1, 4, None, 4]) | ||
|
|
||
| result = arr1 == arr2 | ||
| assert result.equals(con([True, False, False, None, None])) | ||
|
|
||
| result = arr1 != arr2 | ||
| assert result.equals(con([False, True, True, None, None])) | ||
|
|
||
| result = arr1 < arr2 | ||
| assert result.equals(con([False, False, True, None, None])) | ||
|
|
||
| result = arr1 <= arr2 | ||
| assert result.equals(con([True, False, True, None, None])) | ||
|
|
||
| result = arr1 > arr2 | ||
| assert result.equals(con([False, True, False, None, None])) | ||
|
|
||
| result = arr1 >= arr2 | ||
| assert result.equals(con([True, True, False, None, None])) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("typ", ["array", "chunked_array"]) | ||
| def test_compare_scalar(typ): | ||
| if typ == "array": | ||
| def con(values): return pa.array(values) | ||
| else: | ||
| def con(values): return pa.chunked_array([values]) | ||
|
|
||
| arr = con([1, 2, 3, None]) | ||
| # TODO this is a hacky way to construct a scalar .. | ||
| scalar = pa.array([2]).sum() | ||
|
||
|
|
||
| result = arr == scalar | ||
| assert result.equals(con([False, True, False, None])) | ||
|
|
||
| result = arr != scalar | ||
| assert result.equals(con([True, False, True, None])) | ||
|
|
||
| result = arr < scalar | ||
| assert result.equals(con([True, False, False, None])) | ||
|
|
||
| result = arr <= scalar | ||
| assert result.equals(con([True, True, False, None])) | ||
|
|
||
| result = arr > scalar | ||
| assert result.equals(con([False, False, True, None])) | ||
|
|
||
| result = arr >= scalar | ||
| assert result.equals(con([False, True, True, None])) | ||
|
|
||
|
|
||
| def test_compare_chunked_array_mixed(): | ||
|
|
||
| arr = pa.array([1, 2, 3, 4, None]) | ||
| arr_chunked = pa.chunked_array([[1, 2, 3], [4, None]]) | ||
| arr_chunked2 = pa.chunked_array([[1, 2], [3, 4, None]]) | ||
|
|
||
| expected = pa.chunked_array([[True, True, True, True, None]]) | ||
|
|
||
| for result in [ | ||
| arr == arr_chunked, | ||
| arr_chunked == arr, | ||
| arr_chunked == arr_chunked2, | ||
| ]: | ||
| assert result.equals(expected) | ||
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
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.
Maybe factor this out into a helper function to avoid the code duplication?
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.
Moved the
opto function name conversion into a helper function