Numpy 2.X compatibility fixes#1601
Merged
David-Baddeley merged 1 commit intopython-microscopy:masterfrom Jun 6, 2025
Merged
Conversation
- aim is to keep Numpy 1.X backwards compatibility - checking still needed
Contributor
There was a problem hiding this comment.
Need to think about whether it still makes sense to keep / maintain our customised copy of tifffile. I think most, but potentially not all places in the code now use the main tifffile package if it's installed.
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.
Addresses issue of compiling with numpy 2.x mentioned in #1527.
As noted in #1527, numpy 2.X gives compilation errors when attempting to compile several files which stem from subtle changes or dropped deprecated interfaces versus 1.X. The code changes here make PYME compile with latest numpy 2.X while maintaining recent 1.X backwards compatibility.
This PR implements the following changes:
PyArray_XXTYPEtoNPY_XXTYPE, e.g.NPY_DOUBLEetc; this appears backwards compatible with 1.Xgohlke/tifffile.cchange access todtype->elsizetoPyDataType_ELSIZE(dtype)as outlined in https://numpy.org/doc/stable/numpy_2_0_migration_guide.html and include 1.X compatible ifdef'ed macroctypedef np.int_t ...toctypedef np.int64_t ...; apparently this is now required and seems backward compatibleWith this everything builds fine as tested using
Python3.11,numpy2.2.6 andmatplotlib3.10.3.Also ok (backwards compat test) using
Python3.11,numpy1.26.4 andmatplotlib3.8.0.Using numpy 2.X and recent matplotlib (here 3.10.3) most things seem to work fine, I tested briefly
dh5viewline profile plotting which uses thegraphviewpaneland even that seems fine but there may be matplotlib changes that trigger issues as yet unidentified. Similalrly, there are possible numpy 2.X python level interface changes lurking in some not yet tested part of PYME. At least one can now start testing this further.Is this a bugfix or an enhancement?
bug fix for numpy 2.x compatibility
Proposed changes:
As outlined above.
Tested as mentioned above on mac to date.