Pre-import numpy lazy submodules before running tests#90
Merged
SwayamInSync merged 2 commits intoMay 13, 2026
Merged
Conversation
ngoldbaum
approved these changes
May 13, 2026
Member
ngoldbaum
left a comment
There was a problem hiding this comment.
This is fine but can you add a comment with a link to the upstream issue? Hopefully you'll be able to delete this when the next CPython bugfix release happens.
Member
Author
|
Yup will add comment to drop this in future |
Add comments to explain pre-importing numpy's lazy submodules to avoid CPython issue.
Member
Author
|
Merging this in |
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.
Workaround for an upstream CPython bug exposed by our free-threaded CI on
cp3.14t.Why
Our free-threaded CI on
python3.14tstarted failing intest_pandas_strrepwith aRecursionErrorwhose entire stack was insidenumpy/__init__.py's lazy__getattr__recursing onimport numpy.rec as rec. Root cause is a race in CPython'simportlib._bootstrap:_load_unlockedclearsspec._initializing = Falsebefore_find_and_load_unlockedrunssetattr(parent_module, child, module), so the fast path in_find_and_loadreturns the module without the parent attribute under that window. Under free-threaded preemption a second thread reliably observes the window, falls into numpy's lazy__getattr__, runsimport numpy.rec as recagain, fast-paths again, and recurses.Upstream tracking:
__getattr__python/cpython#149728Original failure traceback in this project's CI: #88 (comment)