MNT: replace removed NumPy aliases (np.float/int/object/complex, np.infty) for NumPy >=1.24/2.0 compatibility#92
Open
Andrew Bae (werdnabae) wants to merge 1 commit into
Conversation
NumPy 1.24 removed the deprecated builtin-type aliases (np.float, np.int, np.object, np.complex) and NumPy 2.0 removed np.infty. Since requirements.txt installs an unpinned (current) NumPy, these names raise AttributeError at runtime, breaking large parts of the package. Replace them with the exact equivalents the NumPy migration guide recommends: np.float/np.int/np.object/np.complex -> the Python builtins they aliased, and np.infty -> np.inf. These substitutions are behavior-preserving. Done with a tokenize-based pass so only real code is touched; occurrences in comments and string literals are left unchanged. np.in1d is intentionally NOT changed here because np.isin differs in output shape and needs case-by-case review. Continues the cleanup from NSLS2#81 and NSLS2#90. 106 substitutions across 23 files. All modified files compile. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Replace NumPy aliases that have been removed from modern NumPy and now raise
AttributeErrorat runtime:np.float,np.int,np.object,np.complex— removed in NumPy 1.24 (Dec 2022)np.infty— removed in NumPy 2.0requirements.txtlistsnumpyunpinned, so installs pull a current NumPy (≥1.24, typically 2.x). With that NumPy, any code path hitting one of these names crashes, e.g.:This affects a lot of the package —
np.objectalone appears ~54 times (XSVS/speckle probability arrays, correlation code, etc.).What changed
Each removed name is replaced with the exact equivalent recommended by the NumPy 1.20/2.0 migration guides, so the changes are behavior-preserving:
np.floatfloatnp.intintnp.objectobjectnp.complexcomplexnp.inftynp.inf106 substitutions across 23 files.
How it was done (and what was not touched)
tokenize-based pass, so only real code tokens are rewritten — occurrences inside comments and string literals are left unchanged (e.g. the# removed depreciated np.floatnote and commented-out code are preserved).np.in1dwas intentionally left alone. It is also deprecated, butnp.isinis not a drop-in rename (it preserves the input shape rather than flattening), so it deserves a separate, case-by-case PR.np.int_,np.float64,np.object_,np.intpare untouched (still valid).Verification
python -m py_compile).Continues the NumPy cleanup from #81 and #90.