Repository navigation
Description
Describe the bug and give evidence about its user-facing impact
The latest scikit-learn and scipy nightlies are incompatible with each other. Trying to import from scikit-learn in an environment where they're installed results in an error like this:
TypeError: C function scipy.linalg.cython_blas.dasum has wrong signature (expected __pyx_t_5scipy_6linalg_11cython_blas_d (int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, int *), got __pyx_t_5scipy_6linalg_11cython_blas_d (__pyx_t_5scipy_6linalg_11cython_blas_blas_int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, __pyx_t_5scipy_6linalg_11cython_blas_blas_int *))
Steps/Code to Reproduce
Ran the following today on an aarch64 system:
docker run \
--rm \
-it python:3.13 \
bash
pip install \
--prefer-binary \
--extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
'scikit-learn>=1.9.dev0' \
'scipy>=1.18.dev0'Just importing sklearn.metrics.cluster was enough to trigger the issue
$ python -c "from sklearn.metrics import cluster"
Traceback (most recent call last):
File "<string>", line 1, in <module>
from sklearn.metrics import cluster
File "/usr/local/lib/python3.13/site-packages/sklearn/metrics/__init__.py", line 6, in <module>
from sklearn.metrics import cluster
File "/usr/local/lib/python3.13/site-packages/sklearn/metrics/cluster/__init__.py", line 28, in <module>
from sklearn.metrics.cluster._unsupervised import (
...<4 lines>...
)
File "/usr/local/lib/python3.13/site-packages/sklearn/metrics/cluster/_unsupervised.py", line 13, in <module>
from sklearn.metrics.pairwise import (
...<3 lines>...
)
File "/usr/local/lib/python3.13/site-packages/sklearn/metrics/pairwise.py", line 19, in <module>
from sklearn.metrics._pairwise_distances_reduction import ArgKmin
File "/usr/local/lib/python3.13/site-packages/sklearn/metrics/_pairwise_distances_reduction/__init__.py", line 94, in <module>
from sklearn.metrics._pairwise_distances_reduction._dispatcher import (
...<6 lines>...
)
File "/usr/local/lib/python3.13/site-packages/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py", line 12, in <module>
from sklearn.metrics._pairwise_distances_reduction._argkmin import ArgKmin32, ArgKmin64
File "sklearn/metrics/_pairwise_distances_reduction/_argkmin.pyx", line 1, in init sklearn.metrics._pairwise_distances_reduction._argkmin
File "sklearn/metrics/_pairwise_distances_reduction/_base.pyx", line 1, in init sklearn.metrics._pairwise_distances_reduction._base
File "sklearn/utils/_cython_blas.pyx", line 1, in init sklearn.utils._cython_blas
TypeError: C function scipy.linalg.cython_blas.dasum has wrong signature (expected __pyx_t_5scipy_6linalg_11cython_blas_d (int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, int *), got __pyx_t_5scipy_6linalg_11cython_blas_d (__pyx_t_5scipy_6linalg_11cython_blas_blas_int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, __pyx_t_5scipy_6linalg_11cython_blas_blas_int *))Expected Results
Imports like the following should succeed:
from sklearn.model_selection import BaseCrossValidator, GroupKFold, StratifiedKFoldThis is taken from the stack trace of the LightGBM CI job that caught this: https://github.com/lightgbm-org/LightGBM/actions/runs/23438762347/job/68214781982?pr=7167
Reproducible example above uses from sklearn.metrics import cluster because that seems like the closest public-API import to the bug.
Actual Results
Those imports fail with the error reported above.
Versions
Output of `pip freeze`:
joblib==1.5.3
numpy==2.4.3
scikit-learn==1.9.dev0
scipy==1.18.0.dev0
threadpoolctl==3.6.0Interest in fixing the bug
No, sorry, and I do not have an idea of how to fix it right now.
It looks like something similar happened about 2 years ago, and the root cause ended up being a change in scipy:
Activity
[-]Issue w/ latest scipy nightlies: "C function scipy.linalg.cython_blas.dasum has wrong signature"[/-][+]Issue w/ latest nightlies: "C function scipy.linalg.cython_blas.dasum has wrong signature"[/+]lorentzenchr commentedon Mar 24, 2026
@jameslamb Thanks for this bug report.
It might be related with scipy/scipy#24800.
thomasjpfan commentedon Mar 24, 2026
rgommers@3aae51d#diff-32606644e94405c6b1e71ef8bead9e0072e899b8ee65b90ea5f0cdaf187b525d is a good starting point for a fix.
The above would get us to compile with SciPy 1.18.dev0 and run on the same version. With the above approach, compiling with SciPy 1.18.dev0 and running on SciPy 1.17.1 errors with:
This is the inverse error message where the 1.18.dev0 compiled function expected
blas_int*but we gave itint*at runtime. This is expected given how the function was compiled.thomasjpfan commentedon Mar 28, 2026
This is also an issue with currently released versions of scikit-learn. This error appears with
scipy==1.18.0.dev0andscikit-learn==1.8.0:When
scipy1.18 gets released, older released versions of scikit-learn will not be compatible with it. The minimum fix is to put a upper bound onscipyon the1.8.Xbranch.lorentzenchr commentedon Mar 28, 2026
@scikit-learn/core-devs ping for awareness. We are are currently incompatible with scipy 1.18 (still unreleased).
jjerphan commentedon Mar 29, 2026
It seems that SciPy performed changes which alter the interfaces for BLAS.
Accepting this new version of SciPy would break forward-compatibility (previous builds of scikit-learn won't be compatible with new builds of SciPy) and backward-compatibility (builds of scikit-learn built against the new version of SciPy won't be compatible with previous build of SciPy).
IMO, the best pathway is to revert the changes in SciPy for now and see whether the newly introduced interfaces for BLAS could come as additions rather than as replacements.
rgommers commentedon Mar 29, 2026
I'll investigate today. I already have a branch that adds full support for ILP64 to scikit-learn, but I didn't expect this issue, since it looks like it occurs with a regular LP64 nightly, which should have been a backwards compatible change. It might be a "Cython being braindead about signatures" issue again, which would be bad - if it thinks these two are incompatible, I might have to go back to the drawing board for a bit:
rgommers commentedon Mar 29, 2026
Please don't do that in a release, we need to fix it on the SciPy side.
lorentzenchr commentedon Mar 29, 2026
I think we should be precise in the differences of runtime (backward/forward) compatibility and compile time compat.
As I understand, it‘s a compile time issue.Seems the other way around, it compiles but importing (=runtime) fails.@rgommers Many thanks for your support on this.
rgommers commentedon Mar 29, 2026
Correct after your correction above @lorentzenchr. Compile time I tested before merging the SciPy PR, but I didn't test the
import-from-older-sklearn one unfortunately. This is another case where ABI compatibility is very obviously maintained, but Cython generates naive checks that choke on the differences in the.pxdanyway.I think it's not too hard to fix, but I want to fix the gap in SciPy CI with it, or we'll keep running into these unpleasant surprises.
rgommers commentedon Mar 29, 2026
Fix with regression tests at scipy/scipy#24938.
rgommers commentedon Mar 30, 2026
New scipy nightly wheels are up at https://anaconda.org/channels/scientific-python-nightly-wheels/packages/scipy/files, so this should be fixed now. Please let me know if you still see a problem somewhere.
jeremiedbb commentedon Mar 30, 2026
Thanks a lot @rgommers !
I just tested installing scipy's and sklearn's nightly builds and it seems to work fine
Waiting confirmation from @jameslamb before closing the issue.
jameslamb commentedon Mar 30, 2026
From my perspective, this is resolved and this issue can be closed.
details (click me)
Tested in LightGBM:
Thanks very much!