Skip to content

Commit

Permalink
validate dtype on ContinuousWavelet creation
Browse files Browse the repository at this point in the history
TST: add tests for ContinuousWavelet dtypes
  • Loading branch information
grlee77 committed Mar 27, 2020
1 parent 0b99d56 commit a10c3b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pywt/_extensions/_pywt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ cdef public class ContinuousWavelet [type ContinuousWaveletType, object Continuo
# builtin wavelet
self.name = name.lower()
self.dt = dtype
if np.dtype(self.dt) not in [np.float32, np.float64]:
raise ValueError(
"Only np.float32 and np.float64 dtype are supported for "
"ContinuousWavelet objects.")
if len(self.name) >= 4 and self.name[:4] in ['cmor', 'shan', 'fbsp']:
base_name = self.name[:4]
if base_name == self.name:
Expand Down
15 changes: 15 additions & 0 deletions pywt/tests/test_cwt_wavelets.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ def test_gaus():
assert_allclose(X, x)


@pytest.mark.parametrize('dtype', [np.float32, np.float64])
def test_continuous_wavelet_dtype(dtype):
wavelet = pywt.ContinuousWavelet('cmor1.5-1.0', dtype)
int_psi, x = pywt.integrate_wavelet(wavelet)
assert int_psi.real.dtype == dtype
assert x.dtype == dtype


def test_continuous_wavelet_invalid_dtype():
with pytest.raises(ValueError):
pywt.ContinuousWavelet('gaus5', np.complex64)
with pytest.raises(ValueError):
pywt.ContinuousWavelet('gaus5', np.int)


def test_cgau():
LB = -5
UB = 5
Expand Down

0 comments on commit a10c3b6

Please sign in to comment.