Skip to content

Commit 1256291

Browse files
committed
Merge pull request #150 from grlee77/doctest_fixes
merging this as is for now. Discuss potential improvements for a future release in #151
2 parents 23cb559 + cbb3677 commit 1256291

16 files changed

Lines changed: 226 additions & 205 deletions

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ before_install:
5656
- set -o pipefail
5757

5858
script:
59-
- python -u $OPTIMIZE runtests.py -g -m full --coverage
59+
- python -u $OPTIMIZE runtests.py -g -m full --coverage --doctests

doc/source/dev/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Tests are implemented with `nose`_, so use one of:
2828

2929
$ nosetests pywt
3030

31-
>>> pywt.test()
31+
>>> pywt.test() # doctest: +SKIP
3232

3333

3434
Running tests with Tox

doc/source/ref/idwt-inverse-discrete-wavelet-transform.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Single level ``idwt``
2020
>>> import pywt
2121
>>> (cA, cD) = pywt.dwt([1,2,3,4,5,6], 'db2', 'smooth')
2222
>>> print pywt.idwt(cA, cD, 'db2', 'smooth')
23-
[ 1. 2. 3. 4. 5. 6.]
23+
array([ 1., 2., 3., 4., 5., 6.])
2424

2525
One of the neat features of :func:`idwt` is that one of the *cA* and *cD*
2626
arguments can be set to ``None``. In that situation the reconstruction will be
@@ -36,7 +36,7 @@ Single level ``idwt``
3636
>>> A = pywt.idwt(cA, None, 'db2', 'smooth')
3737
>>> D = pywt.idwt(None, cD, 'db2', 'smooth')
3838
>>> print A + D
39-
[ 1. 2. 3. 4. 5. 6.]
39+
array([ 1., 2., 3., 4., 5., 6.])
4040

4141

4242
Multilevel reconstruction using ``waverec``

doc/source/ref/wavelets.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,17 @@ Built-in wavelets - ``wavelist()``
134134

135135
>>> import pywt
136136
>>> wavelet = pywt.Wavelet('db1')
137-
>>> print wavelet
137+
>>> print(wavelet)
138138
Wavelet db1
139139
Family name: Daubechies
140140
Short name: db
141141
Filters length: 2
142142
Orthogonal: True
143143
Biorthogonal: True
144144
Symmetry: asymmetric
145-
>>> print format_array(wavelet.dec_lo), format_array(wavelet.dec_hi)
145+
>>> print(format_array(wavelet.dec_lo), format_array(wavelet.dec_hi))
146146
[0.70710678118655, 0.70710678118655] [-0.70710678118655, 0.70710678118655]
147-
>>> print format_array(wavelet.rec_lo), format_array(wavelet.rec_hi)
147+
>>> print(format_array(wavelet.rec_lo), format_array(wavelet.rec_hi))
148148
[0.70710678118655, 0.70710678118655] [0.70710678118655, -0.70710678118655]
149149

150150

doc/source/regression/dwt-idwt.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ the ``db2`` wavelet. It's simple..
1818
And the approximation and details coefficients are in ``cA`` and ``cD``
1919
respectively:
2020

21-
>>> print cA
21+
>>> print(cA)
2222
[ 5.65685425 7.39923721 0.22414387 3.33677403 7.77817459]
23-
>>> print cD
23+
>>> print(cD)
2424
[-2.44948974 -1.60368225 -4.44140056 -0.41361256 1.22474487]
2525

2626
Inverse Discrete Wavelet Transform
@@ -29,7 +29,7 @@ Inverse Discrete Wavelet Transform
2929
Now let's do an opposite operation
3030
- :func:`Inverse Discrete Wavelet Transform <idwt>`:
3131

32-
>>> print pywt.idwt(cA, cD, 'db2')
32+
>>> print(pywt.idwt(cA, cD, 'db2'))
3333
[ 3. 7. 1. 1. -2. 5. 4. 6.]
3434

3535
Voilà! That's it!
@@ -44,9 +44,9 @@ border effect handling:
4444

4545
>>> w = pywt.Wavelet('sym3')
4646
>>> cA, cD = pywt.dwt(x, wavelet=w, mode='constant')
47-
>>> print cA
47+
>>> print(cA)
4848
[ 4.38354585 3.80302657 7.31813271 -0.58565539 4.09727044 7.81994027]
49-
>>> print cD
49+
>>> print(cD)
5050
[-1.33068221 -2.78795192 -3.16825651 -0.67715519 -0.09722957 -0.07045258]
5151

5252
Note that the output coefficients arrays length depends not only on the input
@@ -91,9 +91,9 @@ doing :func:`DWT <dwt>` and :func:`IDWT <idwt>`. Otherwise, it will produce
9191
>>> x
9292
[3, 7, 1, 1, -2, 5, 4, 6]
9393
>>> cA, cD = pywt.dwt(x, wavelet=w, mode='periodization')
94-
>>> print pywt.idwt(cA, cD, 'sym3', 'symmetric') # invalid mode
94+
>>> print(pywt.idwt(cA, cD, 'sym3', 'symmetric')) # invalid mode
9595
[ 1. 1. -2. 5.]
96-
>>> print pywt.idwt(cA, cD, 'sym3', 'periodization')
96+
>>> print(pywt.idwt(cA, cD, 'sym3', 'periodization'))
9797
[ 3. 7. 1. 1. -2. 5. 4. 6.]
9898

9999

@@ -107,21 +107,21 @@ Now some tips & tricks. Passing ``None`` as one of the coefficient arrays
107107
parameters is similar to passing a *zero-filled* array. The results are simply
108108
the same:
109109

110-
>>> print pywt.idwt([1,2,0,1], None, 'db2', 'symmetric')
110+
>>> print(pywt.idwt([1,2,0,1], None, 'db2', 'symmetric'))
111111
[ 1.19006969 1.54362308 0.44828774 -0.25881905 0.48296291 0.8365163 ]
112112

113-
>>> print pywt.idwt([1, 2, 0, 1], [0, 0, 0, 0], 'db2', 'symmetric')
113+
>>> print(pywt.idwt([1, 2, 0, 1], [0, 0, 0, 0], 'db2', 'symmetric'))
114114
[ 1.19006969 1.54362308 0.44828774 -0.25881905 0.48296291 0.8365163 ]
115115

116-
>>> print pywt.idwt(None, [1, 2, 0, 1], 'db2', 'symmetric')
116+
>>> print(pywt.idwt(None, [1, 2, 0, 1], 'db2', 'symmetric'))
117117
[ 0.57769726 -0.93125065 1.67303261 -0.96592583 -0.12940952 -0.22414387]
118118

119-
>>> print pywt.idwt([0, 0, 0, 0], [1, 2, 0, 1], 'db2', 'symmetric')
119+
>>> print(pywt.idwt([0, 0, 0, 0], [1, 2, 0, 1], 'db2', 'symmetric'))
120120
[ 0.57769726 -0.93125065 1.67303261 -0.96592583 -0.12940952 -0.22414387]
121121

122122
Remember that only one argument at a time can be ``None``:
123123

124-
>>> print pywt.idwt(None, None, 'db2', 'symmetric')
124+
>>> print(pywt.idwt(None, None, 'db2', 'symmetric'))
125125
Traceback (most recent call last):
126126
...
127127
ValueError: At least one coefficient parameter must be specified.
@@ -133,7 +133,7 @@ Coefficients data size in :attr:`idwt`
133133
When doing the :func:`IDWT <idwt>` transform, usually the coefficient arrays
134134
must have the same size.
135135

136-
>>> print pywt.idwt([1, 2, 3, 4, 5], [1, 2, 3, 4], 'db2', 'symmetric')
136+
>>> print(pywt.idwt([1, 2, 3, 4, 5], [1, 2, 3, 4], 'db2', 'symmetric'))
137137
Traceback (most recent call last):
138138
...
139139
ValueError: Coefficients arrays must have the same size.

doc/source/regression/modes.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Import :mod:`pywt` first
1818

1919
List of available signal extension :ref:`modes <Modes>`:
2020

21-
>>> print pywt.Modes.modes
21+
>>> print(pywt.Modes.modes)
2222
['zero', 'constant', 'symmetric', 'periodic', 'smooth', 'periodization']
2323

2424

@@ -27,10 +27,11 @@ Test that :func:`dwt` and :func:`idwt` can be performed using every mode:
2727
>>> x = [1,2,1,5,-1,8,4,6]
2828
>>> for mode in pywt.Modes.modes:
2929
... cA, cD = pywt.dwt(x, 'db2', mode)
30-
... print "Mode:", mode
31-
... print "cA:", format_array(cA)
32-
... print "cD:", format_array(cD)
33-
... print "Reconstruction:", pywt.idwt(cA, cD, 'db2', mode)
30+
... print("Mode: %s" % mode)
31+
... print("cA: " + format_array(cA))
32+
... print("cD: " + format_array(cD))
33+
... print("Reconstruction: " + format_array(
34+
... pywt.idwt(cA, cD, 'db2', mode)))
3435
Mode: zero
3536
cA: [-0.03468 1.73309 3.40612 6.32929 6.95095]
3637
cD: [-0.12941 -2.156 -5.95035 -1.21545 -1.8625 ]
@@ -70,10 +71,11 @@ You can also refer to modes via :ref:`Modes <Modes>` class attributes:
7071
>>> for mode_name in ['zero', 'constant', 'symmetric', 'periodic', 'smooth', 'periodization']:
7172
... mode = getattr(pywt.Modes, mode_name)
7273
... cA, cD = pywt.dwt([1,2,1,5,-1,8,4,6], 'db2', mode)
73-
... print "Mode:", mode, "(%s)" % mode_name
74-
... print "cA:", format_array(cA)
75-
... print "cD:", format_array(cD)
76-
... print "Reconstruction:", pywt.idwt(cA, cD, 'db2', mode)
74+
... print("Mode: %d (%s)" % (mode, mode_name))
75+
... print("cA: " + format_array(cA))
76+
... print("cD: " + format_array(cD))
77+
... print("Reconstruction: " + format_array(
78+
... pywt.idwt(cA, cD, 'db2', mode)))
7779
Mode: 0 (zero)
7880
cA: [-0.03468 1.73309 3.40612 6.32929 6.95095]
7981
cD: [-0.12941 -2.156 -5.95035 -1.21545 -1.8625 ]
@@ -103,20 +105,20 @@ You can also refer to modes via :ref:`Modes <Modes>` class attributes:
103105
The default mode is :ref:`symmetric <Modes.symmetric>`:
104106

105107
>>> cA, cD = pywt.dwt(x, 'db2')
106-
>>> print cA
108+
>>> print(cA)
107109
[ 1.76776695 1.73309178 3.40612438 6.32928585 7.77817459]
108-
>>> print cD
110+
>>> print(cD)
109111
[-0.61237244 -2.15599552 -5.95034847 -1.21545369 1.22474487]
110-
>>> print pywt.idwt(cA, cD, 'db2')
112+
>>> print(pywt.idwt(cA, cD, 'db2'))
111113
[ 1. 2. 1. 5. -1. 8. 4. 6.]
112114

113115

114116
And using a keyword argument:
115117

116118
>>> cA, cD = pywt.dwt(x, 'db2', mode='symmetric')
117-
>>> print cA
119+
>>> print(cA)
118120
[ 1.76776695 1.73309178 3.40612438 6.32928585 7.77817459]
119-
>>> print cD
121+
>>> print(cD)
120122
[-0.61237244 -2.15599552 -5.95034847 -1.21545369 1.22474487]
121-
>>> print pywt.idwt(cA, cD, 'db2')
123+
>>> print(pywt.idwt(cA, cD, 'db2'))
122124
[ 1. 2. 1. 5. -1. 8. 4. 6.]

doc/source/regression/multilevel.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Multilevel DWT decomposition
1212
>>> x = [3, 7, 1, 1, -2, 5, 4, 6]
1313
>>> db1 = pywt.Wavelet('db1')
1414
>>> cA3, cD3, cD2, cD1 = pywt.wavedec(x, db1)
15-
>>> print cA3
15+
>>> print(cA3)
1616
[ 8.83883476]
17-
>>> print cD3
17+
>>> print(cD3)
1818
[-0.35355339]
19-
>>> print cD2
19+
>>> print(cD2)
2020
[ 4. -3.5]
21-
>>> print cD1
21+
>>> print(cD1)
2222
[-2.82842712 0. -4.94974747 -1.41421356]
2323

2424
>>> pywt.dwt_max_level(len(x), db1)
@@ -31,7 +31,7 @@ Multilevel IDWT reconstruction
3131
------------------------------
3232

3333
>>> coeffs = pywt.wavedec(x, db1)
34-
>>> print pywt.waverec(coeffs, db1)
34+
>>> print(pywt.waverec(coeffs, db1))
3535
[ 3. 7. 1. 1. -2. 5. 4. 6.]
3636

3737

@@ -40,21 +40,21 @@ Multilevel SWT decomposition
4040

4141
>>> x = [3, 7, 1, 3, -2, 6, 4, 6]
4242
>>> (cA2, cD2), (cA1, cD1) = pywt.swt(x, db1, level=2)
43-
>>> print cA1
43+
>>> print(cA1)
4444
[ 7.07106781 5.65685425 2.82842712 0.70710678 2.82842712 7.07106781
4545
7.07106781 6.36396103]
46-
>>> print cD1
46+
>>> print(cD1)
4747
[-2.82842712 4.24264069 -1.41421356 3.53553391 -5.65685425 1.41421356
4848
-1.41421356 2.12132034]
49-
>>> print cA2
49+
>>> print(cA2)
5050
[ 7. 4.5 4. 5.5 7. 9.5 10. 8.5]
51-
>>> print cD2
51+
>>> print(cD2)
5252
[ 3. 3.5 0. -4.5 -3. 0.5 0. 0.5]
5353

5454
>>> [(cA2, cD2)] = pywt.swt(cA1, db1, level=1, start_level=1)
55-
>>> print cA2
55+
>>> print(cA2)
5656
[ 7. 4.5 4. 5.5 7. 9.5 10. 8.5]
57-
>>> print cD2
57+
>>> print(cD2)
5858
[ 3. 3.5 0. -4.5 -3. 0.5 0. 0.5]
5959

6060
>>> coeffs = pywt.swt(x, db1)

doc/source/regression/wavelet.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The :func:`wavelist` function with family name passed as an argument is used to
2626
obtain the list of wavelet names in each family.
2727

2828
>>> for family in pywt.families():
29-
... print "%s family:" % family, ', '.join(pywt.wavelist(family))
29+
... print("%s family: " % family + ', '.join(pywt.wavelist(family)))
3030
haar family: haar
3131
db family: db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, db11, db12, db13, db14, db15, db16, db17, db18, db19, db20
3232
sym family: sym2, sym3, sym4, sym5, sym6, sym7, sym8, sym9, sym10, sym11, sym12, sym13, sym14, sym15, sym16, sym17, sym18, sym19, sym20
@@ -62,7 +62,7 @@ First, let's try printing a :class:`Wavelet` object. This shows a brief
6262
information about its name, its family name and some properties like
6363
orthogonality and symmetry.
6464

65-
>>> print w
65+
>>> print(w)
6666
Wavelet db3
6767
Family name: Daubechies
6868
Short name: db
@@ -79,7 +79,7 @@ corresponds to lowpass and highpass decomposition filters and lowpass and
7979
highpass reconstruction filters respectively:
8080

8181
>>> def print_array(arr):
82-
... print "[%s]" % ", ".join(["%.14f" % x for x in arr])
82+
... print("[%s]" % ", ".join(["%.14f" % x for x in arr]))
8383

8484
>>> print_array(w.dec_lo)
8585
[0.03522629188210, -0.08544127388224, -0.13501102001039, 0.45987750211933, 0.80689150931334, 0.33267055295096]
@@ -101,11 +101,11 @@ Other Wavelet's properties are:
101101

102102
Wavelet :attr:`~Wavelet.name`, :attr:`~Wavelet.short_family_name` and :attr:`~Wavelet.family_name`:
103103

104-
>>> print w.name
104+
>>> print(w.name)
105105
db3
106-
>>> print w.short_family_name
106+
>>> print(w.short_family_name)
107107
db
108-
>>> print w.family_name
108+
>>> print(w.family_name)
109109
Daubechies
110110

111111
- Decomposition (:attr:`~Wavelet.dec_len`) and reconstruction
@@ -125,7 +125,7 @@ Other Wavelet's properties are:
125125

126126
- Symmetry (:attr:`~Wavelet.symmetry`):
127127

128-
>>> print w.symmetry
128+
>>> print(w.symmetry)
129129
asymmetric
130130

131131
- Number of vanishing moments for the scaling function *phi*
@@ -166,7 +166,7 @@ Now when we know a bit about the builtin Wavelets, let's see how to create
166166
Note that such custom wavelets **will not** have all the properties set
167167
to correct values:
168168

169-
>>> print my_wavelet
169+
>>> print(my_wavelet)
170170
Wavelet My Haar Wavelet
171171
Family name:
172172
Short name:
@@ -180,7 +180,7 @@ to correct values:
180180
>>> my_wavelet.orthogonal = True
181181
>>> my_wavelet.biorthogonal = True
182182

183-
>>> print my_wavelet
183+
>>> print(my_wavelet)
184184
Wavelet My Haar Wavelet
185185
Family name:
186186
Short name:

0 commit comments

Comments
 (0)