Describe the bug
test_rmsd.py fails with numpy >=2.4
==================================== ERRORS ====================================
___________________ ERROR collecting tests/mmtf/test_rmsd.py ___________________
tests/mmtf/test_rmsd.py:29: in <module>
p1t48.read_mmtf(TESTDATA_1t48)
biopandas/mmtf/pandas_mmtf.py:55: in read_mmtf
df = self._mmtf_to_df(self.mmtf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
biopandas/mmtf/pandas_mmtf.py:65: in _mmtf_to_df
return mmtf_to_df(mmtf_obj)
^^^^^^^^^^^^^^^^^^^^
biopandas/mmtf/pandas_mmtf.py:585: in mmtf_to_df
int(np.argwhere(np.array(model_indices) > ch_idx)[0]) + 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E TypeError: only 0-dimensional arrays can be converted to Python scalars
=========================== short test summary info ============================
ERROR tests/mmtf/test_rmsd.py - TypeError: only 0-dimensional arrays can be c...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
Steps/Code to Reproduce
If I understand correctly, this change from numpy 1.25, which became enforced in numpy 2.4, is the cause:
https://numpy.org/doc/2.0/release/1.25.0-notes.html
Only ndim-0 arrays are treated as scalars. NumPy used to treat all arrays of size 1 (e.g., np.array([3.14])) as scalars. In the future, this will be limited to arrays of ndim 0 (e.g., np.array(3.14)). The following expressions will report a deprecation warning:
Example:
[chemonke@nixos:~/biopandas]$ python3
Python 3.14.3 (main, Feb 3 2026, 15:32:20) [GCC 15.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.4.4'
>>> import numpy as np
... x = np.arange(4)
... x
...
array([0, 1, 2, 3])
>>> int(np.argwhere(x>1)[0])
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
int(np.argwhere(x>1)[0])
~~~^^^^^^^^^^^^^^^^^^^^^
TypeError: only 0-dimensional arrays can be converted to Python scalars
>>> int(np.argwhere(x>1)[0][0])
...
2
>>>
This line still uses the deprecated behavior
int(np.argwhere(np.array(model_indices) > ch_idx)[0]) + 1
https://github.com/BioPandas/biopandas/blob/main/biopandas/mmtf/pandas_mmtf.py#L585
which can be fixed by explicitly selecting the scalar index value
int(np.argwhere(np.array(model_indices) > ch_idx)[0][0]) + 1
Expected Results
Actual Results
Versions
Verified on an cloud instance running Ubuntu, so this is not an issue with NixOS being weird.
biopandas 0.5.1
Linux-6.12.47-x86_64-with-glibc2.39
Python 3.14.4 (main, May 1 2026, 05:51:55) [GCC 13.3.0]
NumPy 2.4.6
PRETTY_NAME="Ubuntu 24.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.4 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
Describe the bug
test_rmsd.pyfails with numpy >=2.4Steps/Code to Reproduce
If I understand correctly, this change from numpy 1.25, which became enforced in numpy 2.4, is the cause:
https://numpy.org/doc/2.0/release/1.25.0-notes.html
Example:
This line still uses the deprecated behavior
int(np.argwhere(np.array(model_indices) > ch_idx)[0]) + 1https://github.com/BioPandas/biopandas/blob/main/biopandas/mmtf/pandas_mmtf.py#L585
which can be fixed by explicitly selecting the scalar index value
int(np.argwhere(np.array(model_indices) > ch_idx)[0][0]) + 1Expected Results
Actual Results
Versions
Verified on an cloud instance running Ubuntu, so this is not an issue with NixOS being weird.
biopandas 0.5.1
Linux-6.12.47-x86_64-with-glibc2.39
Python 3.14.4 (main, May 1 2026, 05:51:55) [GCC 13.3.0]
NumPy 2.4.6
PRETTY_NAME="Ubuntu 24.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.4 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo