-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
MAINT: add input validation to scales
argument to cwt
#703
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the issue report and PR @cyschneck. This looks close to right, however it'd be more robust to check for negative values to. scales
should contain only positive numbers. So I suggest to:
- Use
if np.any(scales <= 0):
as the criterion - Also test with an input that has a negative scale value
And while we're at it, this check on lines 118-119 doesn't look very robust:
if np.isscalar(scales):
scales = np.array([scales])
Can you please replace that with an unconditional:
scales = np.asarray(scales)
?
With the unconditional conversion for scales
I added a ValueError if the scale was not given as a array_like (list/np.array), which enforces the
|
Note that array-like includes scalars (and anything else that The problem from the second commit was:
So probably the right solution is to use |
I pushed a rebase with that suggestion - let's see if we can get this merged:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, CI is happy and this should be robust. Let's give it a go - thanks @cyschneck!
scales
argument to cwt
Overview
Warning for when using invalid scale range that includes zero which is easy to accidentally do when setting up scales dynamically and would be nice to fail gracefully.
Bug and Steps to Reproduce
When running an invalid scale range (that includes zero), pywt throws an unrelated IndexError
Throws:
This error actually originates on pywt/_cwt.py:150 when attempting to divide by the scale. If the scale range includes zero then it will attempt to divide by zero. However, this error is hidden by casting with astype.
For example, the example below should throw a divide by zero issue, but doesn't. It instead returns an empty array. As a result, trying to index by the empty array on line 154 will throw
IndexError: index -9223372036854775808 is out of bounds for axis 0 with size 1024
For example:
Solution
Throw relevant ValueError when attempting to use a scale that includes zero