Repository navigation
Conversation
Unbox the actual array scalar before mismatch and difference calculations, matching the existing equality path. Implementation and local verification performed with OpenAI Codex assistance; pending human review.
Codex assisted the implementation and verification of the NumPy integer failure-diagnostics fix. L-zeus reviewed the changes and reproduced the bug. Co-authored-by: Codex <noreply@openai.com>
This branch has not been deployed
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.
Problem
When comparing NumPy integer arrays with
pytest.approx(), the failure message can show incorrect differences or fail to render because of integer overflow.For example, comparing
np.uint8(255)with0should report an absolute difference of255. However, the failure-reporting path performs arithmetic on a fixed-width NumPy scalar, which can overflow.The comparison result itself is correct. The problem is limited to how the failure details are calculated.
Change
The existing comparison path already converts NumPy scalars to Python values using
_unbox_numpy_scalar().This change reuses that helper in
ApproxNumpy._repr_compare()before calculating the differences.It fixes the reported values without changing the equality comparison or tolerance calculations.
Tests
Added regression tests covering:
uint8,int8,uint64, andint64boundary values.-Werror.I reproduced the issue on the original code and checked the result after applying the fix. The failure message now reports the correct absolute difference of
255and relative difference of1.0.Codex ran the automated checks on the submission branch:
testing/python/approx.py: 187 passed.AI assistance and review
I used OpenAI Codex to assist with the implementation and automated testing.
I reviewed the source changes and regression tests, checked why the comparison path was already correct while the failure-reporting path could overflow, and reproduced the before-and-after behavior locally.
I understand the change and will handle review feedback and any necessary follow-up changes myself. Codex is also credited in a follow-up commit