Skip to content

Closes #5111: numpy operations alignment tests - #5121

Merged
ajpotts merged 2 commits into
Bears-R-Us:mainfrom
ajpotts:5111_numpy_operations_alignment_tests
Dec 22, 2025
Merged

ajpotts merged 2 commits into
Bears-R-Us:mainfrom
ajpotts:5111_numpy_operations_alignment_tests

Conversation

@ajpotts

@ajpotts ajpotts commented Dec 5, 2025 •

Copy link
Copy Markdown
Contributor

PR: Add Comprehensive NumPy-Alignment Test Suite for Unary, Binary, and Comparison Operators

This PR introduces a complete NumPy-alignment test suite for Arkouda’s pdarray operator semantics.
It adds a new test module:

tests/numpy/alignment_verification/operators_alignment.py

and registers it in pytest.ini, ensuring it runs as part of the standard NumPy compatibility test suite.


What This PR Does

1. Adds a full operator-alignment test suite

The new module tests:

Binary arithmetic operators

  • +, -, *, /, //, %, **
  • Bitwise ops: <<, >>, &, |, ^

Scalar broadcasting

  • array ⊗ scalar
  • scalar ⊗ array

Comparison operators

  • ==, !=, <, <=, >, >=

Unary operators

  • +a (pos)
  • -a (neg)
  • ~a (invert)

This suite validates that Arkouda’s operator implementations match NumPy semantics exactly across int64, uint64, float64, and bool_ dtypes.


Key capabilities tested

Accurate dtype handling

  • Booleans excluded from inappropriate arithmetic combinations
  • Float-specific behaviors (truediv, exponent ranges, invert not allowed)
  • uint64 and int64 power and shift constraints

Shift and power safety

The suite constrains RHS values for operators like:

  • pow (limits exponent size)
  • lshift / rshift (enforces nonnegative RHS)

NumPy-equivalent error handling

Some operations are skipped when NumPy does not support them, ensuring test intent matches NumPy’s behavior.


File Changes

pytest.ini

Adds the new module to Arkouda’s NumPy test paths.

tests/numpy/alignment_verification/operators_alignment.py

A 227‑line comprehensive alignment suite covering:

  • Operator correctness
  • Broadcasting
  • Unary behavior parity
  • Boolean handling
  • Edge-case domain constraints
  • Type-reflection between NumPy arrays and Arkouda pdarrays

✔ Why This Is Important

This suite provides Arkouda with:

1. A single source of truth for NumPy operator semantics

All operator behavior is now validated rigorously and uniformly.

2. A foundation for correcting bugs

The suite already uncovered several issues:

  • Large-shift semantic mismatch for rshift(int64)
  • Incorrect uint64 negation behavior
  • Boolean negation allowing invalid NumPy operations
  • NumPy-alignment issues for pow(scalar, array)

3. A roadmap for missing operator coverage

The test suite makes gaps visible, e.g.:

  • Missing __pos__
  • Missing __abs__
  • Incomplete error alignment for booleans
  • Missing ufunc‑style operator wrappers

4. Reproducibility

All tests use deterministic PRNG behavior (SEED = 314159).


Follow-Up Work (Suggested)

  • Fix bugs uncovered by this suite
  • Add tests for missing operators once implemented
  • Implement NumPy-aligned error paths for bool and uint64 unary ops
  • Complete operator API coverage (__pos__, __abs__, divmod, in-place ops, etc.)

Summary

This PR significantly strengthens Arkouda’s NumPy compatibility guarantees by adding a comprehensive, easy‑to‑extend test suite that verifies operator semantics end‑to‑end across all supported dtypes.

It lays the groundwork for aligning Arkouda more closely with NumPy behavior and making operator support more predictable, correct, and testable.

Closes #5111: numpy operations alignment tests

@ajpotts
ajpotts force-pushed the 5111_numpy_operations_alignment_tests branch from 3b67ec8 to 49cac3c Compare December 16, 2025 22:45
@ajpotts
ajpotts marked this pull request as ready for review December 17, 2025 12:24

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

@ajpotts
ajpotts force-pushed the 5111_numpy_operations_alignment_tests branch from 49cac3c to 54cba3f Compare December 18, 2025 22:25
ajpotts added a commit that referenced this pull request Dec 18, 2025
…ics (#5124)

Since both of these are unary operators and in light of the testing
framework in PR #5121, I thought I would bundle both the negation
changes for `uint64` and `bool` together.

For unary negation on `uint64`, twos complement suggests that the way to
handle this is to negate the bits and add 1.

For unary negation on `bool`, the solution suggested was to raise a
`TypeError` and suggest using `~` instead or `logical_not`, but since
`logical_not` did not exist, I added it and have it pointing at `~`
since they seem to largely be the same thing. I think additional tests
specific to `logical_not` would be unnecessary if `~` is being tested
because it's literally a wrapper for `~`. However, I did grab the unit
tests from PR #5121 that seem relevant to this PR.

Closes #5117: Unary Negation on ak.uint64 Does Not Match Numpy Semantics
Closes #5119: Bug: Unary Negation (-a) on ak.bool_ Does Not Match NumPy
Semantics

Co-authored-by: ajpotts <[email protected]>
@ajpotts
ajpotts force-pushed the 5111_numpy_operations_alignment_tests branch from 9255553 to 13def6f Compare December 19, 2025 11:37

@jaketrookman jaketrookman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good

@ajpotts
ajpotts added this pull request to the merge queue Dec 22, 2025
Merged via the queue into Bears-R-Us:main with commit 86e1bf0 Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numpy operations alignment tests

3 participants