X Tutup
Skip to content

Catch specgram warnings during tests #7985

Merged
QuLogic merged 6 commits intomatplotlib:masterfrom
DietBru:fix_specgram_Userwarning
Feb 6, 2017
Merged

Catch specgram warnings during tests #7985
QuLogic merged 6 commits intomatplotlib:masterfrom
DietBru:fix_specgram_Userwarning

Conversation

@DietBru
Copy link
Copy Markdown
Contributor

@DietBru DietBru commented Jan 29, 2017

This catches the specgram() warning introduced in #7845 in test_mlab. Also an additional test was added to check if the warning is raised. Closes #7967.

'07/09/83 5:17:34 PM\n' +
'06/20/2054 2:31:45 PM\n' +
'10/31/00 11:50:23 AM\n')
'03/05/76 12:00:01 AM\n' +
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You may as well remove the "+" to rely on implicit string concatenation.

assert spec.shape[1] == self.t_specgram.shape[0]

def test_specgram_warn_only1seg(self):
"""Warning should be raised if len(x) <= len(NFFT). """
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

<= NFFT I think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Of Course. Thanks.

Copy link
Copy Markdown
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

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

Looks good, apart from the extra warning statement needed

def test_specgram_warn_only1seg(self):
"""Warning should be raised if len(x) <= NFFT. """
with warnings.catch_warnings(record=True) as w:
mlab.specgram(x=self.y, NFFT=len(self.y), Fs=self.Fs)
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.

Just before this line will need a line with

warnings.simplefilter('always')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. Thanks.

@dstansby dstansby changed the title Catch specgram warnings during tests [MRG+1] Catch specgram warnings during tests Feb 2, 2017
@dstansby
Copy link
Copy Markdown
Member

dstansby commented Feb 2, 2017

This all looks good now.

To reviewer+1: I can't get the old warnings to appear using pytest on master anymore, does anyone know why this is?

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Feb 2, 2017

I think pytest does a better job of capturing output than nose did; you can try passing -s or --capture=no to have it not swallow output. We might also consider the pytest-warnings plugin in the future to capture and summarize these things.

@dstansby
Copy link
Copy Markdown
Member

dstansby commented Feb 2, 2017

Yep, I'm picking them up with the pytest-warnings plugin now.

@QuLogic QuLogic changed the title [MRG+1] Catch specgram warnings during tests Catch specgram warnings during tests Feb 6, 2017
@QuLogic QuLogic merged commit 6a46f04 into matplotlib:master Feb 6, 2017
@QuLogic QuLogic added this to the 2.1 (next point release) milestone Feb 6, 2017
@DietBru DietBru deleted the fix_specgram_Userwarning branch February 6, 2017 23:58
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Jun 1, 2017
The nosig_complex_twosided_nopad_to and nosig_complex_defaultsided_nopad_to
tests appear to have been mistakes, because they repeat the parameters
used in nosig_complex_twosided_noNFFT_no_pad_to and
nosig_complex_defaultsided_noNFFT_no_pad_to, so change `None` to `-1`.

The nosig_complex_defaultsided_trim test was somehow not causing
warnings and thus not "fixed" by matplotlib#7985, but change it `len_x=1024` and
`NFFT_density=512` to be consistent with the other tests.

The nosig_complex_defaultsided_oddlen test has always been different
from its sibling tests and I suspect it was an accident, so change
`NFFT_density` to 33.

Fixes matplotlib#8393.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Jun 2, 2017
The nosig_complex_twosided_nopad_to and nosig_complex_defaultsided_nopad_to
tests appear to have been mistakes, because they repeat the parameters
used in nosig_complex_twosided_noNFFT_no_pad_to and
nosig_complex_defaultsided_noNFFT_no_pad_to, so change `None` to `-1`.

The nosig_complex_defaultsided_trim test was somehow not causing
warnings and thus not "fixed" by matplotlib#7985, but change it `len_x=1024` and
`NFFT_density=512` to be consistent with the other tests.

The nosig_complex_defaultsided_oddlen test has always been different
from its sibling tests and I suspect it was an accident, so change
`NFFT_density` to 33.

Fixes matplotlib#8393.
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.

4 participants

X Tutup