nipy / nibabel

Python package to access a cacophony of neuro-imaging file formats
http://nipy.org/nibabel/
Other
634 stars 258 forks source link

MAINT: Fix for NumPy 2.0 #1303

Closed larsoner closed 4 months ago

larsoner commented 4 months ago

Might fix https://github.com/mne-tools/mne-python/actions/runs/8127208745/job/22227091689?pr=12478#step:17:365 :

mne/_freesurfer.py:144: in _get_mri_info_data
    out["data"] = np.array(mgz.dataobj)
E   TypeError: ArrayProxy.__array__() got an unexpected keyword argument 'copy'

This was in MNE-Python with a MGZ file, but I imagine many tests using scientific-python-nightly-wheels in nibabel will fail similarly without this. @effigies or others feel free to close this or push directly if other changes are needed if it's easier than commenting!

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.17%. Comparing base (e4facc1) to head (11cf547).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1303 +/- ## ========================================== - Coverage 92.27% 92.17% -0.10% ========================================== Files 99 99 Lines 12460 12460 Branches 2561 2561 ========================================== - Hits 11497 11485 -12 - Misses 641 648 +7 - Partials 322 327 +5 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

effigies commented 4 months ago

This looks painful. np.array(copy=False)-equivalent behavior is being changed to np.array(copy=None) in 2.0 with no deprecation period.

Also, the type checking for the updated types will only work if mypy and numpy 2.0-dev are installed into the same environment. I think we're going to need to see if we can drop our custom ArrayLike protocol and use numpy's directly. I can't immediately see another way to work with types that differ between stable and dev versions.

larsoner commented 4 months ago

😨

Okay I'll leave that to another PR then! Hopefully it ends up being less painful than it sounds