TST: Add tests for PyUFunc_ReplaceLoopBySignature#31097
Merged
seberg merged 3 commits intonumpy:mainfrom Apr 10, 2026
Merged
Conversation
Add C test helpers (replace_loop/restore_loop) in _umath_tests that replace a ufunc's float64 loop with one that always outputs 42.0. Python tests verify: - Replaced loop is actually called (output is 42.0, not normal result) - Replacement works after the ufunc has been called (caches populated) - Original loop is correctly restored The test_replace_after_use test is specifically designed to catch bugs where loop caching optimizations fail to invalidate on replacement. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
86b03e2 to
7c6ca27
Compare
seberg
approved these changes
Apr 9, 2026
Member
seberg
left a comment
There was a problem hiding this comment.
Thanks for adding this test, probably best to have if we want to touch things here (and even if we deprecated easy to remove).
A bit scary to use a real ufunc, but should be OK. (Although if there is a testing one around, and you feel like it...)
Either way, the only real thing is that this test isn't thread safe, so needs the marker.
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
seberg
approved these changes
Apr 10, 2026
Member
seberg
left a comment
There was a problem hiding this comment.
Thanks, if things change and the test is outdated it should be easy to follow-up!
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.
PR summary
Add C test helpers (
replace_loop/restore_loop) that replace a ufunc's float64 loop with one that always outputs 42.0.Python tests verify:
AI Disclosure
Claude was instructed to create a test based on #31068 (comment). Afterwards the test was manually cleaned and made more specific.