Repository navigation
GH-55893: [Python] Add reflected arithmetic operators to Scalar and Array - #55949
Open
dhaanish597 wants to merge 3 commits into
Open
dhaanish597 wants to merge 3 commits into
dhaanish597 wants to merge 3 commits into
Conversation
tadeja
requested changes
Dec 3, 2026
| (operator.or_, 7), (operator.xor, 5), (operator.lshift, 48), | ||
| (operator.rshift, 0), | ||
| ]) | ||
| def test_reflected_arithmetic(factory, operation, expected): |
Member
There was a problem hiding this comment.
@dhaanish597 any special reason that you created a separate new file for the test?
See the initial implementation of arithmetic on arrays and scalars and try to follow the same style #48085
a19f13b
Author
There was a problem hiding this comment.
Thanks, Tadeja! I moved the tests into test_array.py and test_scalars.py to match the original PR. Both files passed locally.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rationale for this change
PyArrow scalars and arrays support operations such as
x + 2, but the equivalent expression2 + xraisesTypeError.What changes are included in this PR?
Add the ten reflected operators listed in the issue to
ScalarandArray, with matching type annotations. Dispatch to the existing compute kernels with operands in their original order, including for subtraction, division, powers, and shifts.Are these changes tested?
On a native macOS arm64 build of the pinned source: 22 new regression tests and 24 existing arithmetic tests passed. The focused stub runtime test passed, and mypy found no issues in 26 source files. The full suite was not run locally.
Are there any user-facing changes?
Python numbers can now appear on the left of the supported operators. Unsupported operand types still raise
TypeError.Was AI used for this PR?
OpenAI ChatGPT (Dot) assisted with reproduction and generated the implementation, tests, type-stub changes, and PR draft. The contributor personally reviewed the patch before submission.
PR code and description written by:
Reviewed before submission by: