Skip to content

Numba __init__.py not catching incompatible NumPy version early enough #8718

Closed

Description

@stuartarchibald

Reporting a bug

  • I have tried using the latest released version of Numba (most recent is
    visible in the change log (https://github.com/numba/numba/blob/main/CHANGE_LOG).
  • I have included a self contained code sample to reproduce the problem.
    i.e. it's possible to run as 'python bug.py'.

Following on from numerous issues reported against #8615, no released version of Numba is compatible with NumPy 1.24, this is stated in the docs e.g.:

| 0.56.4 | 2022-11-03 | 3.7.x <= version < 3.11 | 1.18 <= version < 1.24 | 0.39.x | 11.x | 2021.x |

The problem in practice seems to be as follows:

  1. As of the version tags on the release0.56 branch of Numba (though this also probably impacts all Numba versions), all builds made against these tags are not compatible with NumPy 1.24 due to some changes in NumPy ufunc objects, see NumPy 1.24 #8691 for necessary adjustments. Essentially the resolve_dtypes method was added which tripped a piece of guard code in Numba that returns -1 without an Exception being set, this manifests as a SystemError on import of the C extension containing this code.
  2. Tools installing Numba wheels e.g. pip are not constrained by the maximum NumPy version in metadata as they are in conda packages. The mechanism to prevent use of incompatible installations in this case is to raise an Exception at runtime from Numba's __init__.py:

    numba/numba/__init__.py

    Lines 133 to 155 in 288a38b

    def _ensure_critical_deps():
    """
    Make sure Python, NumPy and SciPy have supported versions.
    """
    from numba.np.numpy_support import numpy_version
    from numba.core.utils import PYVERSION
    if PYVERSION < (3, 7):
    raise ImportError("Numba needs Python 3.7 or greater")
    if numpy_version < (1, 18):
    raise ImportError("Numba needs NumPy 1.18 or greater")
    elif numpy_version > (1, 23):
    raise ImportError("Numba needs NumPy 1.23 or less")
    try:
    import scipy
    except ImportError:
    pass
    else:
    sp_version = tuple(map(int, scipy.__version__.split('.')[:2]))
    if sp_version < (1, 0):
    raise ImportError("Numba requires SciPy version 1.0 or greater")
    called here:
    _ensure_critical_deps()

I think the issue is that the mechanism in 2. fails if a C extension with the problem in 1. is imported as part of Numba's __init__ ahead of the call to _ensure_critical_deps. i.e. the check for compatibility of dependencies is too late.

Activity

  1. added this to the Numba 0.57 RC milestone on Jan 18, 2023
  2. added a commit that references this issue on Jan 25, 2023
    d1cc6fc
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