Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bb9725

Browse files
committed
MAINT: Escalate import warning to an import error
Now that pybind11 has the 2.12 release we can escalate the warning to an error here.
1 parent e1bf1d6 commit 8bb9725

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

numpy/core/_multiarray_umath.py

+14-30
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,34 @@ def __getattr__(attr_name):
1414
from ._utils import _raise_warning
1515

1616
if attr_name in {"_ARRAY_API", "_UFUNC_API"}:
17-
from numpy.version import short_version, release
17+
from numpy.version import short_version
1818
import textwrap
1919
import traceback
2020
import sys
2121

2222
msg = textwrap.dedent(f"""
2323
A module that was compiled using NumPy 1.x cannot be run in
2424
NumPy {short_version} as it may crash. To support both 1.x and 2.x
25-
versions of NumPy, modules must be compiled against NumPy 2.0.
25+
versions of NumPy, modules must be compiled with NumPy 2.0.
26+
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
2627
2728
If you are a user of the module, the easiest solution will be to
28-
either downgrade NumPy or update the failing module (if available).
29+
downgrade to 'numpy<2' or try to upgrade the affected module.
30+
We expect that some modules will need time to support NumPy 2.
2931
3032
""")
31-
if not release and short_version.startswith("2.0.0"):
32-
# TODO: Can remove this after the release.
33-
msg += textwrap.dedent("""\
34-
NOTE: When testing against pre-release versions of NumPy 2.0
35-
or building nightly wheels for it, it is necessary to ensure
36-
the NumPy pre-release is used at build time.
37-
The main way to ensure this is using no build isolation
38-
and installing dependencies manually with NumPy.
39-
40-
If your dependencies have the issue, check whether they
41-
build nightly wheels build against NumPy 2.0.
42-
43-
pybind11 note: If you see this message and do not see
44-
any errors raised, it's possible this is due to a
45-
package using an old version of pybind11 that should be
46-
updated.
47-
48-
""")
49-
msg += "Traceback (most recent call last):"
33+
tb_msg = "Traceback (most recent call last):"
5034
for line in traceback.format_stack()[:-1]:
5135
if "frozen importlib" in line:
5236
continue
53-
msg += line
54-
# Only print the message. This has two reasons (for now!):
55-
# 1. Old NumPy replaced the error here making it never actually show
56-
# in practice, thus raising alone would not be helpful.
57-
# 2. pybind11 simply reaches into NumPy internals and requires a
58-
# new release that includes the fix. That is missing as of 2023-11.
59-
# But, it "conveniently" ignores the ABI version.
60-
sys.stderr.write(msg)
37+
tb_msg += line
38+
39+
# Also print the message (with traceback). This is because old versions
40+
# of NumPy unfortunately set up the import to replace (and hide) the
41+
# error. The traceback shouldn't be needed, but e.g. pytest plugins
42+
# seem to swallow it and we should be failing anyway...
43+
sys.stderr.write(msg + tb_msg)
44+
raise ImportError(msg)
6145

6246
ret = getattr(_multiarray_umath, attr_name, None)
6347
if ret is None:

0 commit comments

Comments
 (0)