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
16 changes: 12 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
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 @@ -130,7 +130,11 @@ jobs:
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
python util/refguide_check.py
# doctests docstrings
pytest --doctest-modules --pyargs pywt -v --doctest-collect=api
# doctest *rst tutorials
pytest --doctest-glob=*rst doc/source/regression/ -v
# Run Sphinx HTML docs builder, converting warnings to errors
pip install -r util/readthedocs/requirements.txt
ev-br marked this conversation as resolved.
Show resolved Hide resolved
ev-br marked this conversation as resolved.
Show resolved Hide resolved
sphinx-build -b html -W --keep-going -d _build/doctrees . doc/source doc/build
ev-br marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -203,7 +207,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 +225,11 @@ jobs:
pytest --pyargs pywt
python ../pywt/tests/test_doc.py
elif [ "${REFGUIDE_CHECK}" == "1" ]; then
python util/refguide_check.py --doctests
python util/refguide_check.py
# doctests docstrings
pytest --doctest-modules --pyargs pywt -v --doctest-collect=api
# doctest *rst tutorials
pytest --doctest-glob=*rst doc/source/regression/ -v
else
pytest --pyargs pywt
fi
Expand Down
12 changes: 6 additions & 6 deletions doc/source/regression/wp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ First, start with a tree decomposition at level 2. Leaf nodes in the tree are:
>>> dummy = wp.get_level(2)
>>> for n in wp.get_leaf_nodes(False):
... print(n.path, format_array(n.data))
aa [ 5. 13.]
aa [ 5. 13.]
ad [-2. -2.]
da [-1. -1.]
dd [ 0. 0.]
dd [0. 0.]

>>> node = wp['ad']
>>> print(node)
Expand All @@ -242,9 +242,9 @@ The leaf nodes that left in the tree are:

>>> for n in wp.get_leaf_nodes():
... print(n.path, format_array(n.data))
aa [ 5. 13.]
aa [ 5. 13.]
da [-1. -1.]
dd [ 0. 0.]
dd [0. 0.]

And the reconstruction is:

Expand All @@ -260,10 +260,10 @@ tree:

>>> for n in wp.get_leaf_nodes(False):
... print(n.path, format_array(n.data))
aa [ 5. 13.]
aa [ 5. 13.]
ad [-2. -2.]
da [-1. -1.]
dd [ 0. 0.]
dd [0. 0.]

>>> print(wp.reconstruct())
[ 1. 2. 3. 4. 5. 6. 7. 8.]
Expand Down
24 changes: 12 additions & 12 deletions doc/source/regression/wp2d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,23 +407,23 @@ Lazy evaluation:
via decomposition of its parent node (the wp object itself).

>>> print(wp['a'])
a: [[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]]
a: [[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]]

3) Now the ``a`` is set to the newly created node:

>>> print(wp.a)
a: [[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]]
a: [[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]
[ 3. 7. 11. 15.]]

And so is `wp.d`:

>>> print(wp.d)
d: [[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]]
d: [[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
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
2 changes: 1 addition & 1 deletion pywt/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest


def pytest_configure(config):
config.addinivalue_line("markers",
"slow: Tests that are slow.")

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