Skip to content

BUG: raise a clear error when cwt() is given a discrete wavelet (gh-776)#849

Merged
rgommers merged 1 commit into
PyWavelets:mainfrom
gaoflow:cwt-discrete-wavelet-error
Jun 9, 2026
Merged

BUG: raise a clear error when cwt() is given a discrete wavelet (gh-776)#849
rgommers merged 1 commit into
PyWavelets:mainfrom
gaoflow:cwt-discrete-wavelet-error

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #776.

cwt(data, scales, 'coif1') (or any other discrete wavelet) crashed with:

AttributeError: 'pywt._extensions._pywt.Wavelet' object has no attribute 'complex_cwt'

The name is resolved with DiscreteContinuousWavelet, which happily returns
a discrete Wavelet for a name like 'coif1'. cwt then unconditionally
reads wavelet.complex_cwt, an attribute that only exists on
ContinuousWavelet, so the call dies with the confusing error above instead
of telling the user they passed the wrong kind of wavelet.

As @rgommers noted on the issue, passing the wrong wavelet name should give a
clear message rather than a confusing one. This validates that the resolved
wavelet is continuous and otherwise raises a ValueError that names the
offending wavelet and points to pywt.wavelist(kind='continuous'):

ValueError: cwt() requires a continuous wavelet, but 'coif1' is a discrete
wavelet. Use a continuous wavelet such as those returned by
pywt.wavelist(kind='continuous') (e.g. 'morl', 'mexh', 'cmor').

A regression test covering a name, a discrete Wavelet instance, and a
still-working continuous wavelet is included.

…veletsgh-776)

Passing a discrete wavelet, e.g. cwt(data, scales, 'coif1'), crashed with
a confusing `AttributeError: 'Wavelet' object has no attribute
'complex_cwt'`, because `complex_cwt` exists only on ContinuousWavelet.

Validate that the resolved wavelet is continuous and otherwise raise a
ValueError that names the offending wavelet and points to
pywt.wavelist(kind='continuous').
@rgommers rgommers added this to the v1.10.0 milestone Jun 9, 2026

@rgommers rgommers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks @gaoflow.

@rgommers rgommers merged commit cb30da3 into PyWavelets:main Jun 9, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cwt always fails with the message AttributeError: 'pywt._extensions._pywt.Wavelet' object has no attribute 'comple x_cwt'

2 participants