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

Use scipy-doctest instead of refguide-check #747

Merged
merged 13 commits into from
Jun 25, 2024
19 changes: 11 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
MINIMUM_REQUIREMENTS: [0]
USE_SCIPY: [0]
USE_SDIST: [0]
REFGUIDE_CHECK: [0]
REFGUIDE_CHECK: [1]
PIP_FLAGS: [""]
OPTIONS_NAME: ["default"]
include:
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
python -m build --sdist
pip install dist/pyw*.tar.gz -v
elif [ "${REFGUIDE_CHECK}" == "1" ]; then
pip install sphinx numpydoc
pip install sphinx numpydoc scipy-doctest
pip install . -v
else
pip install . -v
Expand All @@ -129,11 +129,13 @@ jobs:
pytest --pyargs pywt
python ../pywt/tests/test_doc.py
elif [ "${REFGUIDE_CHECK}" == "1" ]; then
# Run doctests and check if the refguide contains entries from __all__
python util/refguide_check.py --doctests
# doctest docstrings
pytest --doctest-modules --pyargs pywt -v --doctest-collect=api
# Run Sphinx HTML docs builder, converting warnings to errors
pip install -r util/readthedocs/requirements.txt
sphinx-build -b html -W --keep-going -d _build/doctrees . doc/source doc/build
cd ..
# XXX sphinx build is broken on CI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here? Debug left-over, or is something actually broken right now? If so, I think three lines can be safely deleted. The separate CI job to build the docs with the ReadTheDocs integration is green.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RTD job is not building the docs with -W, I guess: python -m sphinx -T -b html -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/html. Not that there are any warnings because we're already warning-free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this sphinx-build incantation did not previously run on CI because REFGUIDE-CHECK: [0], and was always broken. There's a standing offer to fix this in a follow-up though :-). #747 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks, let's do that - offer is appreciated:)

# pip install -r util/readthedocs/requirements.txt
# sphinx-build -b html -W --keep-going -d _build/doctrees . doc/source doc/build
else
pytest --pyargs pywt
fi
Expand Down Expand Up @@ -203,7 +205,7 @@ jobs:
python -m build --sdist
pip install pywavelets* -v
elif [ "${REFGUIDE_CHECK}" == "1" ]; then
pip install sphinx numpydoc
pip install sphinx numpydoc scipy-doctest
pip install . -v
else
pip install . -v
Expand All @@ -221,7 +223,8 @@ jobs:
pytest --pyargs pywt
python ../pywt/tests/test_doc.py
elif [ "${REFGUIDE_CHECK}" == "1" ]; then
python util/refguide_check.py --doctests
# doctests docstrings
pytest --doctest-modules --pyargs pywt -v --doctest-collect=api
else
pytest --pyargs pywt
fi
Expand Down
8 changes: 4 additions & 4 deletions pywt/_cwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
>>> x = np.arange(512)
>>> y = np.sin(2*np.pi*x/32)
>>> coef, freqs=pywt.cwt(y,np.arange(1,129),'gaus1')
>>> plt.matshow(coef) # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
>>> plt.matshow(coef)
>>> plt.show()

>>> import pywt
>>> import numpy as np
Expand All @@ -105,8 +105,8 @@ def cwt(data, scales, wavelet, sampling_period=1., method='conv', axis=-1):
>>> widths = np.arange(1, 31)
>>> cwtmatr, freqs = pywt.cwt(sig, widths, 'mexh')
>>> plt.imshow(cwtmatr, extent=[-1, 1, 1, 31], cmap='PRGn', aspect='auto',
... vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max()) # doctest: +SKIP
>>> plt.show() # doctest: +SKIP
... vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max())
>>> plt.show()
"""

# accept array_like input; make a copy to ensure a contiguous array
Expand Down
32 changes: 12 additions & 20 deletions pywt/_extensions/_pywt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _Modes(object):
--------
>>> import pywt
>>> pywt.Modes.modes
['zero', 'constant', 'symmetric', 'reflect', 'periodic', 'smooth', 'periodization', 'antisymmetric', 'antireflect']
['zero', 'constant', 'symmetric', 'periodic', 'smooth', 'periodization', 'reflect', 'antisymmetric', 'antireflect']
rgommers marked this conversation as resolved.
Show resolved Hide resolved
>>> # The different ways of passing wavelet and mode parameters
>>> (a, d) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
>>> (a, d) = pywt.dwt([1,2,3,4,5,6], pywt.Wavelet('db2'), pywt.Modes.smooth)
Expand Down Expand Up @@ -909,34 +909,26 @@ cdef public class ContinuousWavelet [type ContinuousWaveletType, object Continuo
>>> wavelet.upper_bound = ub
>>> wavelet.lower_bound = lb
>>> [psi,xval] = wavelet.wavefun(length=n)
>>> plt.plot(xval,psi) # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at ...>]
>>> plt.title("Gaussian Wavelet of order 8") # doctest: +ELLIPSIS
<matplotlib.text.Text object at ...>
>>> plt.show() # doctest: +SKIP
>>> plt.plot(xval,psi)
>>> plt.title("Gaussian Wavelet of order 8")
>>> plt.show()

>>> import pywt
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> import pywt
>>> lb = -5
>>> ub = 5
>>> n = 1000
>>> wavelet = pywt.ContinuousWavelet("cgau4")
>>> wavelet.upper_bound = ub
>>> wavelet.lower_bound = lb
>>> [psi,xval] = wavelet.wavefun(length=n)
>>> plt.subplot(211) # doctest: +ELLIPSIS
<matplotlib.axes._subplots.AxesSubplot object at ...>
>>> plt.plot(xval,np.real(psi)) # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at ...>]
>>> plt.title("Real part") # doctest: +ELLIPSIS
<matplotlib.text.Text object at ...>
>>> plt.subplot(212) # doctest: +ELLIPSIS
<matplotlib.axes._subplots.AxesSubplot object at ...>
>>> plt.plot(xval,np.imag(psi)) # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at ...>]
>>> plt.title("Imaginary part") # doctest: +ELLIPSIS
<matplotlib.text.Text object at ...>
>>> plt.show() # doctest: +SKIP
>>> fix, (ax1, ax2) = plt.subplots(2, 1)
>>> ax1.plot(xval,np.real(psi))
>>> ax1.set_title("Real part")
>>> ax2.plot(xval,np.imag(psi))
>>> ax2.set_title("Imaginary part")
>>> plt.show()

"""
cdef pywt_index_t output_length "output_length"
Expand Down
5 changes: 3 additions & 2 deletions pywt/_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def wavedecn(data, wavelet, mode='symmetric', level=None, axes=None):
>>> # Levels:
>>> len(coeffs)-1
2
>>> waverecn(coeffs, 'db1') # doctest: +NORMALIZE_WHITESPACE
>>> waverecn(coeffs, 'db1')
array([[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
Expand Down Expand Up @@ -496,7 +496,7 @@ def waverecn(coeffs, wavelet, mode='symmetric', axes=None):
>>> # Levels:
>>> len(coeffs)-1
2
>>> waverecn(coeffs, 'db1') # doctest: +NORMALIZE_WHITESPACE
>>> waverecn(coeffs, 'db1')
array([[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
Expand Down Expand Up @@ -1415,6 +1415,7 @@ def fswavedecn(data, wavelet, mode='symmetric', levels=None, axes=None):

Examples
--------
>>> import numpy as np
>>> from pywt import fswavedecn
>>> fs_result = fswavedecn(np.ones((32, 32)), 'sym2', levels=(1, 3))
>>> print(fs_result.detail_keys())
Expand Down
20 changes: 10 additions & 10 deletions pywt/data/_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def ascent():

>>> import matplotlib.pyplot as plt
>>> plt.gray()
>>> plt.imshow(ascent) # doctest: +ELLIPSIS
>>> plt.imshow(ascent
rgommers marked this conversation as resolved.
Show resolved Hide resolved
<matplotlib.image.AxesImage object at ...>
>>> plt.show() # doctest: +SKIP
>>> plt.show()

"""
with importlib.resources.as_file(_DATADIR.joinpath('ascent.npz')) as f:
Expand Down Expand Up @@ -73,9 +73,9 @@ def aero():

>>> import matplotlib.pyplot as plt
>>> plt.gray()
>>> plt.imshow(aero) # doctest: +ELLIPSIS
>>> plt.imshow(aero)
<matplotlib.image.AxesImage object at ...>
>>> plt.show() # doctest: +SKIP
>>> plt.show()

"""
with importlib.resources.as_file(_DATADIR.joinpath('aero.npz')) as f:
Expand Down Expand Up @@ -121,9 +121,9 @@ def camera():

>>> import matplotlib.pyplot as plt
>>> plt.gray()
>>> plt.imshow(camera) # doctest: +ELLIPSIS
>>> plt.imshow(camera)
<matplotlib.image.AxesImage object at ...>
>>> plt.show() # doctest: +SKIP
>>> plt.show()

"""
with importlib.resources.as_file(_DATADIR.joinpath('camera.npz')) as f:
Expand Down Expand Up @@ -154,9 +154,9 @@ def ecg():
True

>>> import matplotlib.pyplot as plt
>>> plt.plot(ecg) # doctest: +ELLIPSIS
>>> plt.plot(ecg)
[<matplotlib.lines.Line2D object at ...>]
>>> plt.show() # doctest: +SKIP
>>> plt.show()
"""
with importlib.resources.as_file(_DATADIR.joinpath('ecg.npz')) as f:
ecg = np.load(f)['data']
Expand Down Expand Up @@ -192,9 +192,9 @@ def nino():
True

>>> import matplotlib.pyplot as plt
>>> plt.plot(time,sst) # doctest: +ELLIPSIS
>>> plt.plot(time,sst)
[<matplotlib.lines.Line2D object at ...>]
>>> plt.show() # doctest: +SKIP
>>> plt.show()
"""
with importlib.resources.as_file(_DATADIR.joinpath('sst_nino3.npz')) as f:
sst_csv = np.load(f)['data']
Expand Down
Loading