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

Fix incompatibility with NumPy 1.20 #8187

Merged
merged 3 commits into from
Jul 2, 2024

Conversation

neutrinoceros
Copy link
Contributor

Fixes an incompatibility encountered in the wild when importing Pillow==10.4.0 with numpy==1.20.x installed.

@neutrinoceros neutrinoceros force-pushed the bug/compat/numpy1.20 branch from 7e60e55 to b4ee967 Compare July 1, 2024 17:33
@radarhere
Copy link
Member

NumPy < 1.24 is EOL - https://endoflife.date/numpy

Would an alternative solution be to upgrade NumPy?

@radarhere radarhere added the NumPy label Jul 2, 2024
@radarhere radarhere changed the title BUG: fix an incompatibility with numpy 1.20 Incompatibility with NumPy 1.20 Jul 2, 2024
@neutrinoceros
Copy link
Contributor Author

NumPy < 1.24 is EOL - endoflife.date/numpy

One could argue that numpy < 2.0 is EOL since numpy devs have stated multiple times they cannot backport patches to 1.26 anymore, so I don't think NEP 29 (which I assume is the source for this endoflife page) is to be strictly followed.

The presence of this try/except block seems to indicate an intention to support versions older than 1.24, and it does work with any version but 1.20 , and it's very simple to fix that. I see that Pillow doesn't require numpy so I don't think it's possible to express an incompatibility in metadata (something equivalent to pip-style constraints files), except by requiring Python>=3.10 (numpy 1.21.4 being the first version to support it).
I can add this sort of information in a comment if it helps; my patch can be reverted when Python 3.9 is unsupported.

Would an alternative solution be to upgrade NumPy?

I should note that I discovered this in CI while explicitly testing a library with its minimal requirements (it has matplotlib pinned but not Pillow, since it's not a direct dependency). If this patch is undesired for some reason, bumping minimal requirements is my next best shot, but I'm emphasizing that it's not about a particular virtualenv that would be broken.

@radarhere
Copy link
Member

One could argue that numpy < 2.0 is EOL since numpy devs have stated multiple times they cannot backport patches to 1.26 anymore, so I don't think NEP 29 (which I assume is the source for this endoflife page) is to be strictly followed.

That sounds like an argument for upgrading NumPy, not for staying on an old version.

my patch can be reverted when Python 3.9 is unsupported.

I'm mostly conscious of trying to have some line in the sand, so that we're not supporting old versions forever. If this request is just that we support NumPy 1.20 for the next year though, then that is a limited time frame.

@radarhere radarhere changed the title Incompatibility with NumPy 1.20 Fix type checking with NumPy 1.20 Jul 2, 2024
@neutrinoceros
Copy link
Contributor Author

If this request is just that we support NumPy 1.20 for the next year though, then that is a limited time frame.

Yes, I'm not planning to support Python 3.9 (hence, numpy 1.20) beyond early 2025.

Note that I don't think the new title for this PR is correct: this fixes a runtime crash, type checking isn't the only (or main) concern.

@radarhere
Copy link
Member

radarhere commented Jul 2, 2024

this fixes a runtime crash, type checking isn't the only (or main) concern.

That is surprising - we install NumPy 1.17 in our Ubuntu 20.04 CI, and our test suite runs without a problem.

I'll go further then - neutrinoceros#1 will prevent numpy.typing from being imported unless the user is type checking.

@radarhere radarhere changed the title Fix type checking with NumPy 1.20 Fix incompatibility with NumPy 1.20 Jul 2, 2024
Do not import numpy.typing unless TYPE_CHECKING
@neutrinoceros
Copy link
Contributor Author

neutrinoceros commented Jul 2, 2024

That is surprising - we install NumPy 1.17 in our Ubuntu 20.04 CI, and our test suite runs without a problem.

I'm not surprised: numpy 1.19 and older or 1.21 and newer all work as intended: only version 1.20 has numpy.typing but doesn't have numpy.typing.NDArray.

@hugovk hugovk merged commit ececa9d into python-pillow:main Jul 2, 2024
53 of 55 checks passed
@neutrinoceros neutrinoceros deleted the bug/compat/numpy1.20 branch July 2, 2024 20:51
andife added a commit to onnx/onnx that referenced this pull request Jul 29, 2024
)

### Description
Limit numpy version to <2 in tests to pass ci-piplines for 1.16.2. 

The change in requirements-min.txt is also needed to get the CI's to
pass. There's an issue with the
python-pillow/Pillow#8187. We did try
downgrading the version of pillow but that then failed to build for some
reason.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve? -->
<!-- - If it fixes an open issue, please link to the issue here. -->

Signed-off-by: Andreas Fehlner <fehlner@arcor.de>
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.

3 participants