Skip to content

Update numpy hook for compatibility with 1.22 - #6474

Merged
rokm merged 4 commits into
pyinstaller:developfrom
rokm:fix-scipy-with-numpy-1.22
Jan 2, 2022
Merged

rokm merged 4 commits into
pyinstaller:developfrom
rokm:fix-scipy-with-numpy-1.22

Conversation

@rokm

@rokm rokm commented Jan 2, 2022

Copy link
Copy Markdown
Member

As of numpy 1.22.0, numpy.testing imports numpy.testing._private.extbuild, which in turn imports numpy.distutils and distutils that we explicitly exclude in the hook.

The numpy.testing is imported by scipy.optimize (via scipy.optimize._constraints); therefore, a frozen application using that module and numpy 1.22 ends up with missing numpy.distutils module error, as seen in #6473.

But before we tackle numpy hook itself, the scipy tests need to be cleaned up a bit - the lack of failure on Windows and macOS runners due to xfail does not exactly inspire confidence...

rokm added 2 commits January 2, 2022 18:04
The referenced issues do not seem to be actual anymore. On the
other hand, the xfail annotation hides the fact that scipy tests
end up broken with numpy 1.22.
We are unlikely to encounter scipy < 0.16 under python versions
that we support. The removed version comparison, while harmless
by itself, used distutils.LooseVersion, so removing the check
also allows us to remove dependency on distutils for this
particular test.
@rokm
rokm force-pushed the fix-scipy-with-numpy-1.22 branch from 52e4341 to 4926900 Compare January 2, 2022 17:04
As of numpy 1.22, distutils and numpy.distutils are required by
numpy.testing (due to added import of numpy.testing._private.extbuild),
which in turn is used for example by scipy.optimize (via its
scipy.optimize._constraints module). So we cannot exclude them
anymore, except for earlier numpy versions.
@bwoodsend

Copy link
Copy Markdown
Member

[Sigh], yet again I find myself wishing that NumPy's test suite and building machinery where not part of the NumPy package itself.

@rokm

rokm commented Jan 2, 2022

Copy link
Copy Markdown
Member Author

Yeah, the best part is that scipy is importing numpy.testing for its suppres_warnings context_manager/decorator. Based on the docs for that one, I wonder if they could simply go with warnings.catch_warnings instead...

For python 3.7, use 1.21.5, which is the last release supporting
python 3.7.

Use 1.22 with python 3.8 and newer, including python 3.10.
@bwoodsend

bwoodsend commented Jan 2, 2022 •

Copy link
Copy Markdown
Member

Yeah, the best part is that scipy is importing numpy.testing for its suppres_warnings context_manager/decorator. Based on the docs for that one, I wonder if they could simply go with warnings.catch_warnings instead...

I'll try it as a pull request and see what they say. At the very least, having that dependency knocks up the import scipy initialisation time.

@bwoodsend

Copy link
Copy Markdown
Member

Although, now that I remember that scipy's test suite takes about a day and a half to run, this may take a while.

@rokm
rokm marked this pull request as ready for review January 2, 2022 22:10
@rokm rokm added the needs backport This pull request needs cherry picking onto the v4 branch. label Jan 2, 2022
@rokm

rokm commented Jan 2, 2022 •

Copy link
Copy Markdown
Member Author

This takes care of of numpy.

I noticed scipy 1.8.0 release candidates have also dropped python 3.7 support, and other projects following NEP 29 will likely follow the suit. So perhaps we should pre-emptively pin the python 3.7 dependencies for projects where we already have 3.6-specific pins (e.g., numpy, scipy, matplotlib) to the current version... (And we might also consider retiring 3.6 runners so that all macOS runners take only one cycle).

@bwoodsend

Copy link
Copy Markdown
Member

I imagine that matplotlib and pandas will follow suit but I think I'd rather know than assume that they will. Python 3.6 officially died 8 days ago so we might as well reclaim the 3.6 runners and drop 3.6 support.

@bwoodsend

bwoodsend commented Jan 2, 2022 •

Copy link
Copy Markdown
Member

Yeah, the best part is that scipy is importing numpy.testing for its suppres_warnings context_manager/decorator. Based on the docs for that one, I wonder if they could simply go with warnings.catch_warnings instead...

There are a couple of others which are only loaded by some submodules. But it's the same story for each of them - they're all trivially replaceable.

/e/n/scipy (dont-import-numpy-distutils)> git grep numpy.testing scipy | grep --invert-match /tests
scipy/special/_mptestutils.py:from numpy.testing import assert_
scipy/special/_test_round.pyx:from numpy.testing import assert_
scipy/special/_testutils.py:from numpy.testing import assert_
scipy/stats/_binned_statistic.py:from numpy.testing import suppress_warnings

Although only the last is actually loaded on importing anything public.

@rokm
rokm merged commit 9621355 into pyinstaller:develop Jan 2, 2022
@rokm
rokm deleted the fix-scipy-with-numpy-1.22 branch January 2, 2022 23:20
@rokm rokm added backported Backported to v4 branch and removed needs backport This pull request needs cherry picking onto the v4 branch. labels Jan 2, 2022
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backported Backported to v4 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants