Skip to content

allow string input in dwt_max_level #269

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

Merged
merged 1 commit into from
Jan 15, 2017
Merged

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Jan 10, 2017

I noticed that usage of dwt_max_level with a Wavelet object as the second argument is fairly common, but is not documented. I updated the docstring and modified the function to also accept a string name as well for convenience.

While doing this, I noticed that passing a negative filter_len would cause an OverflowError, while a filter_len of 0 or 1 would not cause an error, but just return 0. I chose to change the behavior so that any filter_len < 2 raises a ValueError.

@grlee77
Copy link
Contributor Author

grlee77 commented Jan 10, 2017

btw... saw the contributing guidelines link while prepping this, so #268 is working as expected!

@codecov-io
Copy link

codecov-io commented Jan 10, 2017

Current coverage is 86.28% (diff: 100%)

Merging #269 into master will increase coverage by 0.05%

@@             master       #269   diff @@
==========================================
  Files            20         20          
  Lines          3043       3056    +13   
  Methods          45         45          
  Messages          0          0          
  Branches        520        525     +5   
==========================================
+ Hits           2624       2637    +13   
  Misses          368        368          
  Partials         51         51          

Powered by Codecov. Last update b3a3200...18fc2bb

assert_(pywt.dwt_max_level(32, 'sym5') == 1)

# string input that is not a discrete wavelet
assert_raises(TypeError, pywt.dwt_max_level, 16, 'mexh')
Copy link
Member

Choose a reason for hiding this comment

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

This should be ValueError with an understandable error message ( `filter_len` is not the name of a discrete wavelet for example.)

Maybe put elif filter_len in wavelist(kind='discrete'): inside an isinstance(filter_len, string_types):? I see we don't have string_types yet; it can be stolen from six if needed.

@rgommers
Copy link
Member

LGTM aside from the TypeError.

@grlee77
Copy link
Contributor Author

grlee77 commented Jan 10, 2017

I have included string_types as implemented in six at the top of _dwt.py. Let me know if you would rather have it located in a separate _utils.py or similar.

I added another case to catch any other non-integer input, although I used np.number instead of np.integer here so a float with integer value would be accepted. A value of 4.4 would now raise a ValueError instead of silently truncating to 4 upon input to _dwt_max_level

can rebase to a single commit prior to merge

@rgommers
Copy link
Member

Had to look this up: numpy/numpy#4547. The numbers ABCs are supported from numpy >= 1.9.0, so this is OK.

May be useful to squash this now before merging.

…e 2nd argument.

update docstring to indicate that a wavelet can be passed in place of the filter length

raise ValueError if filter_len < 2

formerly filter_len = 0 or 1 returned 0 while a negative filter_len raised an OverflowError

raise informative ValueError on unrecognized string or non-integer input
@grlee77
Copy link
Contributor Author

grlee77 commented Jan 14, 2017

okay. it should now be ready for merge

@rgommers rgommers merged commit 47f50e7 into PyWavelets:master Jan 15, 2017
@rgommers
Copy link
Member

Merged, thanks!

@grlee77 grlee77 deleted the max_lev branch July 20, 2018 21:30
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.

3 participants