question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: numpy.testing now depends on numpy.distutils

See original GitHub issue

Describe the issue:

As of numpy 1.22.0, specifically after 1b5b5871c725a5b67b55d29c7361a353d8ae13ef, import numpy.testing implicitly imports numpy.distutils. The exact line that introduced this is https://github.com/numpy/numpy/commit/84e0707afa587e7655410561324ac36085db2b95#diff-657b0df76a18e77d5033e7a763d2e40a58498dee25374a90c4db9850ce2f75d3R13 which appears to load an extension module building helper (utilising numpy.distutils) into the numpy.testing namespace. This is unfortunate because, despite numpy’s own usages of numpy.testing being avoided except when testing, downstream projects do still use it. For example import scipy imports numpy.testing (somewhat unnecessarily IMO but I’ll make that case on their issue tracker) which now drags in numpy.distutils.

Reproduce the code example:

# Attempt to load numpy.testing after blocking imports of `numpy.distutils`.
import sys
sys.modules["numpy.distutils"] = None
import numpy.testing

# Alternatively, you can skip the sys.modules blocking and just run:
import numpy.testing
assert "numpy.distutils" not in sys.modules
# But the first provides a traceback which indicates where the import leak is.

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/brenainn/.local/lib/python3.9/site-packages/numpy/testing/__init__.py", line 12, in <module>
    from ._private import extbuild, decorators as dec
  File "/home/brenainn/.local/lib/python3.9/site-packages/numpy/testing/_private/extbuild.py", line 11, in <module>
    from numpy.distutils.ccompiler import new_compiler
ModuleNotFoundError: No module named 'numpy.distutils.ccompiler'; 'numpy.distutils' is not a package

NumPy/Python version information:

1.22.0 3.9.6 (default, Jul 30 2021, 22:48:59) 
[GCC 11.1.0]

This is specific to numpy 1.22.0. Earlier versions of numpy did not do this.


Note to whoever addresses this: If this is fixed after #20745 is merged then this conditional statement may be made unconditional.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
bwoodsendcommented, Jan 16, 2022

OK, PR inbound…

1reaction
QuLogiccommented, Jan 15, 2022

This also ‘breaks’ downstream test suites that use np.testing in Python 3.10 due to #20225, if they happen to do -Werror.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Guidelines — NumPy v1.24 Manual
Whenever a new bug is found in a routine, you should write a new test for that specific case and add it to...
Read more >
Testing Guidelines — NumPy v1.17 Manual
Well-designed tests with good coverage make an enormous difference to the ease of refactoring. Whenever a new bug is found in a routine,...
Read more >
NumPy 1.20.0 Release Notes
Previously the non-empty index [20] was not checked for correctness. It will now be checked causing a deprecation warning which will be turned...
Read more >
Test Support (numpy.testing) — NumPy v1.24 Manual
Common test support for all numpy test scripts. ... Test if two objects are equal, and print an error message if test fails....
Read more >
NumPy 1.22.0 Release Notes
Distutils forces strict floating point model on clang#. NumPy now sets the -ftrapping-math option on clang to enforce correct floating point error handling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found