Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Escalate import warning to an import error #26149

Merged
merged 3 commits into from Mar 29, 2024

Conversation

seberg
Copy link
Member

@seberg seberg commented Mar 28, 2024

Now that pybind11 has the 2.12 release we can escalate the warning to an error here.


It may make sense (and also be necessary for CI to succeed) to hold off slightly so that most downstream wheels picked up the new pybind11 release.
@ksunden in case you were not aware, pybind11 has the new release now, so we should be good to go (and matplotlib having rebuild with it may be a good "indicator" that we can put this in).

Closes gh-26010

@seberg seberg force-pushed the warn-to-error branch 3 times, most recently from 3fb6d78 to 3094cad Compare March 28, 2024 10:13
@asmeurer
Copy link
Member

This is the before-and-after for me in this branch, importing the latest version of matplotlib (using PYTHONPATH to point to the dev numpy)

before

>>> import matplotlib

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0b1 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled against NumPy 2.0.

If you are a user of the module, the easiest solution will be to
either downgrade NumPy or update the failing module (if available).

Traceback (most recent call last):  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/__init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/colors.py", line 57, in <module>
    from matplotlib import _api, _cm, cbook, scale
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/scale.py", line 22, in <module>
    from matplotlib.ticker import (
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/ticker.py", line 143, in <module>
    from matplotlib import transforms as mtransforms
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/transforms.py", line 49, in <module>
    from matplotlib._path import (
RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/__init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/colors.py", line 57, in <module>
    from matplotlib import _api, _cm, cbook, scale
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/scale.py", line 22, in <module>
    from matplotlib.ticker import (
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/ticker.py", line 143, in <module>
    from matplotlib import transforms as mtransforms
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/transforms.py", line 49, in <module>
    from matplotlib._path import (
ImportError: numpy.core.multiarray failed to import

after

>>> import matplotlib

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.0.dev0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/__init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/colors.py", line 57, in <module>
    from matplotlib import _api, _cm, cbook, scale
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/scale.py", line 22, in <module>
    from matplotlib.ticker import (
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/ticker.py", line 143, in <module>
    from matplotlib import transforms as mtransforms
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/transforms.py", line 49, in <module>
    from matplotlib._path import (
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/__init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/colors.py", line 57, in <module>
    from matplotlib import _api, _cm, cbook, scale
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/scale.py", line 22, in <module>
    from matplotlib.ticker import (
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/ticker.py", line 143, in <module>
    from matplotlib import transforms as mtransforms
  File "/Users/aaronmeurer/miniconda3/envs/array-apis/lib/python3.11/site-packages/matplotlib/transforms.py", line 49, in <module>
    from matplotlib._path import (
ImportError: numpy.core.multiarray failed to import

It seems the only difference is that the more helpful RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000 has been replaced with the less helpful AttributeError: _ARRAY_API not found.

I don't really understand what is going on in that error message. Is something manually printing the first traceback before the real traceback? In IPython, the first traceback is formatted like a normal traceback with no coloring, then the ImportError is formatted like an IPython traceback.

@seberg
Copy link
Member Author

seberg commented Mar 29, 2024

It seems the only difference is that the more helpful

Of course not: matplotlib doesn't use an old pybind11 here which is what this is about. So you can have the old message cryptically pointing to the ABI versions which is a bit nicer, but then you do not have any protection for old pybind usage.

Is something manually printing the first traceback

Clearly, the code diff explains this and why. We can remove the first traceback print but obviously not the error print (hoping that nothing swallows the traceback as pytest seems to do).

@seberg
Copy link
Member Author

seberg commented Mar 29, 2024

FWIW, what is surprising to me is that the error gets replaced with an ImportError somewhere later, since I don't think the NumPy headers do that part, not sure why it should point to NumPy in that import error.

@charris
Copy link
Member

charris commented Mar 29, 2024

This should be backported?

@charris charris merged commit d3eee38 into numpy:main Mar 29, 2024
58 of 62 checks passed
@charris
Copy link
Member

charris commented Mar 29, 2024

Thanks Sebastian.

@rgommers
Copy link
Member

This should be backported?

Yes, that was the plan.

@seberg seberg deleted the warn-to-error branch March 29, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle warning about private API and pybind11 before 2.0.0rc1
4 participants