Skip to content

Issue w/ latest nightlies: "C function scipy.linalg.cython_blas.dasum has wrong signature" #33616

Closed

Description

@jameslamb

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, StratifiedKFold

This 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.0

Interest 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

  1. added
    Needs Triage
    on Mar 23, 2026
  2. changed the title [-]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"[/+] on Mar 23, 2026
  3. lorentzenchr commented on Mar 24, 2026

    @lorentzenchr
    Member

    @jameslamb Thanks for this bug report.
    It might be related with scipy/scipy#24800.

  4. thomasjpfan commented on Mar 24, 2026

    @thomasjpfan
    Member

    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:

    TypeError: C function scipy.linalg.cython_blas.dasum has wrong signature (expected __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 *), got __pyx_t_5scipy_6linalg_11cython_blas_d (int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, int *))

    This is the inverse error message where the 1.18.dev0 compiled function expected blas_int* but we gave it int* at runtime. This is expected given how the function was compiled.

  5. removed
    Needs Triage
    on Mar 24, 2026
  6. added this to the 1.9 milestone on Mar 24, 2026
  7. thomasjpfan commented on Mar 28, 2026

    @thomasjpfan
    Member

    This is also an issue with currently released versions of scikit-learn. This error appears with scipy==1.18.0.dev0 and scikit-learn==1.8.0:

    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 *))

    When scipy 1.18 gets released, older released versions of scikit-learn will not be compatible with it. The minimum fix is to put a upper bound on scipy on the 1.8.X branch.

  8. lorentzenchr commented on Mar 28, 2026

    @lorentzenchr
    Member

    @scikit-learn/core-devs ping for awareness. We are are currently incompatible with scipy 1.18 (still unreleased).

  9. jjerphan commented on Mar 29, 2026

    @jjerphan
    Member

    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.

  10. rgommers commented on Mar 29, 2026

    @rgommers
    Contributor

    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:

    cdef void caxpy(int *n, c *ca, c *cx, int *incx, c *cy, int *incy) noexcept nogil
    
    ctypedef int blas_int
    cdef void caxpy(blas_int *n, c *ca, c *cx, blas_int *incx, c *cy, blas_int *incy) noexcept nogil
    
  11. rgommers commented on Mar 29, 2026

    @rgommers
    Contributor

    When scipy 1.18 gets released, older released versions of scikit-learn will not be compatible with it. The minimum fix is to put a upper bound on scipy on the 1.8.X branch.

    Please don't do that in a release, we need to fix it on the SciPy side.

  12. lorentzenchr commented on Mar 29, 2026

    @lorentzenchr
    Member

    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.

  13. rgommers commented on Mar 29, 2026

    @rgommers
    Contributor

    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 .pxd anyway.

    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.

  14. rgommers commented on Mar 29, 2026

    @rgommers
    Contributor

    Fix with regression tests at scipy/scipy#24938.

  15. rgommers commented on Mar 30, 2026

    @rgommers
    Contributor

    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.

  16. jeremiedbb commented on Mar 30, 2026

    @jeremiedbb
    Member

    Thanks a lot @rgommers !

    I just tested installing scipy's and sklearn's nightly builds and it seems to work fine

    import sklearn
    import scipy
    
    sklearn.__version__
    '1.9.dev0'
    
    scipy.__version__
    '1.18.0.dev0+git20260329.30a63c6'
    
    from sklearn.metrics import cluster
    # no error

    Waiting confirmation from @jameslamb before closing the issue.

  17. jameslamb commented on Mar 30, 2026

    @jameslamb
    ContributorAuthor

    Waiting confirmation from @jameslamb before closing the issue.

    From my perspective, this is resolved and this issue can be closed.

    details (click me)

    Tested in LightGBM:

    $ pip freeze
    cffi==2.0.0
    cloudpickle==3.1.2
    contourpy==1.3.3
    cycler==0.12.1
    fonttools==4.62.1
    iniconfig==2.3.0
    joblib==1.5.3
    kiwisolver==1.5.0
    lightgbm @ file:///opt/lgb-build/dist/lightgbm-4.6.0.99-py3-none-linux_x86_64.whl#sha256=13af44b0567a65ba5729f7ab7c967f10b3a595c4ee37ce6e67a784d40f58532a
    matplotlib==3.11.0.dev2037+g809ad237a
    numpy==2.5.0.dev0
    packaging==26.0
    pandas==3.1.0.dev0+527.g240224f715
    pillow==12.1.1
    pluggy==1.6.0
    psutil==7.2.2
    pyarrow==24.0.0.dev260
    pycparser==3.0
    Pygments==2.20.0
    pyparsing==3.3.2
    pytest==9.0.2
    python-dateutil==2.9.0.post0
    scikit-learn==1.9.dev0
    scipy==1.18.0.dev0
    six==1.17.0
    threadpoolctl==3.6.0

    Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions