nipy / nibabel

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

BUG: Bug with NumPy 2.0 #1318

Open larsoner opened 2 months ago

larsoner commented 2 months ago

Seen on latest MNE-Python CIs

https://github.com/mne-tools/mne-python/actions/runs/8771722469/job/24069839865?pr=12556#step:17:14956

mne/_freesurfer.py:88: in _reorient_image
    orig_data = np.array(img.dataobj).astype(np.float32)
E   DeprecationWarning: __array__ implementation doesn't accept a copy keyword, so passing copy=False failed. __array__ must implement 'dtype' and 'copy' keyword arguments.

This is probably a dup in some form of https://github.com/nipy/nibabel/pull/1303 , but now that 2.0 is in the brief RC period (a few weeks left I think before release since RC landed a few weeks ago?) figured I'd open a proper issue to track it.

effigies commented 2 months ago

Looks like this is showing up in our CI (dev run: https://github.com/nipy/nibabel/actions/runs/8776832524/job/24080913543):

   nibabel/tests/test_arrayproxy.py::test_get_obj_dtype
    /home/runner/work/nibabel/nibabel/nibabel/tests/test_arrayproxy.py:306: DeprecationWarning: __array__ implementation doesn't accept a copy keyword, so passing copy=False failed. __array__ must implement 'dtype' and 'copy' keyword arguments.
      assert get_obj_dtype(np.array(prox)) == np.dtype('float64')

  nibabel/tests/test_arrayproxy.py::test_get_obj_dtype
    /home/runner/work/nibabel/nibabel/nibabel/tests/test_arrayproxy.py:310: DeprecationWarning: __array__ implementation doesn't accept a copy keyword, so passing copy=False failed. __array__ must implement 'dtype' and 'copy' keyword arguments.
      assert get_obj_dtype(np.array(prox)) == np.dtype('int16')

  nibabel/tests/test_arrayproxy.py::test_get_unscaled
    /home/runner/work/nibabel/nibabel/nibabel/tests/test_arrayproxy.py:333: DeprecationWarning: __array__ implementation doesn't accept a copy keyword, so passing copy=False failed. __array__ must implement 'dtype' and 'copy' keyword arguments.
      assert_array_almost_equal(np.array(prox), arr * 2.1 + 3.14)

Should help track it down. Does your group have any time to work on this?

larsoner commented 2 months ago

Based on your previous comment here:

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.

Sounds like the changes are a bit too deep for me I think :frowning_face:

effigies commented 2 months ago

Ugh... I wonder if we should just have a final pre-2.0 release, and then plan to jump to numpy>=2 for the next release. People who need to use older numpy can just use an older nibabel.