This question considers NEP 51, which changed NumPy's string representation. This document describes some potential backward compatibility issues:
An exception to this are downstream libraries with documentation and especially documentation testing. Since the representation of many values will change, in many cases the documentation will have to be updated...
It may be necessary to adopt tools for doctest testing to allow approximate value checking for the new representation.
However, looking at the documentation, I don't see any changes to the output of the examples.
Looking at NumPy's docs, e.g. numpy.sin
:
Print sine of one angle:
>>> np.sin(np.pi/2.) 1.0
But with the latest NumPy, this example shows np.float64(1.0)
.
And similar with SciPy's docs, e.g. scipy.special.erfinv
:
>>> from scipy.special import erfinv, erf >>> erfinv(0.5) 0.4769362762044699
But with the latest NumPy, this example shows np.float64(0.4769362762044699)
.
I'm aware of numpy.set_printoptions
to change this default:
>>> np.set_printoptions(legacy="1.25")
>>> np.sin(np.pi/2.)
1.0
>>> erfinv(0.5)
0.4769362762044699
however, I don't see this being used for either NumPy or SciPy's documentation.
How are these Sphinx docs configured to show the legacy outputs?
For modules with examples, how would pytest doctests be run to pass?
(I.e. using pytest --doctest-modules mymod
)
How are these Sphinx docs configured to show the legacy outputs?
There's no such configuration going on. The example outputs are hardcoded into the NumPy docstrings. They're not generated by running the code every time the docs are built.
You can print the docstrings if you want to see - for example, print(numpy.sin.__doc__)
. You can also look at the source code.
At some point, the NumPy maintainers will probably want to update the docstrings to show the new output. They haven't so far, perhaps because it's a lot of work.