-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Closed
Labels
Description
Describe the issue:
Historic behaviour of np.set_printoptions() was silent:
$ python
Python 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:31:54) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'2.0.1'
>>> np.set_printoptions()
>>> np.set_printoptions(precision=4)
>>> quit()
Reproduce the code example:
As of 2.1.0, it returns a representation of the settings:
$ python
Python 3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:31:54) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
np.__version__
>>> np.__version__
'2.1.0'
>>> np.set_printoptions()
<Token var=<ContextVar name='format_options' default={'edgeitems': 3, 'threshold': 1000, 'floatmode': 'maxprec', 'precision': 8, 'suppress': False, 'linewidth': 75, 'nanstr': 'nan', 'infstr': 'inf', 'sign': '-', 'formatter': None, 'legacy': 9223372036854775807, 'override_repr': None} at 0x105f74f90> at 0x10637e900>
>>> np.set_printoptions(precision=4)
<Token var=<ContextVar name='format_options' default={'edgeitems': 3, 'threshold': 1000, 'floatmode': 'maxprec', 'precision': 8, 'suppress': False, 'linewidth': 75, 'nanstr': 'nan', 'infstr': 'inf', 'sign': '-', 'formatter': None, 'legacy': 9223372036854775807, 'override_repr': None} at 0x105f74f90> at 0x1061df540>
>>> quit()
Error message:
This breaks doctests in code using numpy, e.g. biopython/biopython#4795 (comment)
Python and NumPy Versions:
$ python -c 'import sys, numpy; print(numpy.__version__); print(sys.version)'
2.1.0
3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:31:54) [Clang 16.0.6 ]
Runtime Environment:
$ python -c 'import numpy; numpy.show_runtime()'
[{'numpy_version': '2.1.0',
'python': '3.12.5 | packaged by conda-forge | (main, Aug 8 2024, 18:31:54) '
'[Clang 16.0.6 ]',
'uname': uname_result(system='Darwin', node='Peters-iMac.local', release='21.6.0', version='Darwin Kernel Version 21.6.0: Mon Jun 24 00:56:10 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_X86_64', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL']}},
{'architecture': 'Haswell',
'filepath': '/Users/pc40583/mambaforge/envs/pyani-plus_py312/lib/python3.12/site-packages/numpy/.dylibs/libscipy_openblas64_.dylib',
'internal_api': 'openblas',
'num_threads': 4,
'prefix': 'libscipy_openblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.27'}]
Context for the issue:
This is breaking continuous integration tests using numpy.
The change appears to be unintended, the documentation at https://numpy.org/doc/stable/reference/generated/numpy.set_printoptions.html currently shows the old silent behaviour.
Reactions are currently unavailable