Skip to content

Numpy 2.X compatibility fixes#1601

Merged
David-Baddeley merged 1 commit intopython-microscopy:masterfrom
csoeller:numpy-2-compat
Jun 6, 2025
Merged

Numpy 2.X compatibility fixes#1601
David-Baddeley merged 1 commit intopython-microscopy:masterfrom
csoeller:numpy-2-compat

Conversation

@csoeller
Copy link
Contributor

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:

  • change all PyArray_XXTYPE to NPY_XXTYPE, e.g. NPY_DOUBLE etc; this appears backwards compatible with 1.X
  • in gohlke/tifffile.c change access to dtype->elsize to PyDataType_ELSIZE(dtype) as outlined in https://numpy.org/doc/stable/numpy_2_0_migration_guide.html and include 1.X compatible ifdef'ed macro
  • change occasional ctypedef np.int_t ... to ctypedef np.int64_t ...; apparently this is now required and seems backward compatible

With this everything builds fine as tested using Python 3.11, numpy 2.2.6 and matplotlib 3.10.3.
Also ok (backwards compat test) using Python 3.11, numpy 1.26.4 and matplotlib 3.8.0.

Using numpy 2.X and recent matplotlib (here 3.10.3) most things seem to work fine, I tested briefly dh5view line profile plotting which uses the graphviewpanel and 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.

- aim is to keep Numpy 1.X backwards compatibility
- checking still needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@David-Baddeley David-Baddeley merged commit 6ec75cf into python-microscopy:master Jun 6, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants