Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

TST: Catch possible warnings #2745

Merged
merged 1 commit into from

3 participants

@certik
Owner

See the commit log for more details. Now all tests should always pass on Travis-CI.

@certik
Owner

Ok, I can see already that the "with" statement can't be used since it doesn't work in Python 2.5....

@rgommers
Owner

Like I said on the list but more explicit:

from numpy.testing import WarningManager
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
    warnings.simplefilter('ignore')
    ...
finally:
    warn_ctx.__exit__()
@certik certik TST: Catch possible warnings
Previously the test sometimes fails with the following error:

======================================================================
ERROR: Test a special case for var
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.2/lib/python3.2/site-packages/numpy/ma/tests/test_core.py", line 2731, in test_varstd_specialcases
    _ = method(out=mout)
  File "/home/travis/virtualenv/python3.2/lib/python3.2/site-packages/numpy/ma/core.py", line 4778, in std
    np.power(out, 0.5, out=out, casting='unsafe')
RuntimeWarning: invalid value encountered in power

----------------------------------------------------------------------

Now we catch it, as recommended by the thread:

http://old.nabble.com/Should-abs(-nan-)-be-supported--td34389839.html
2d841a8
@certik
Owner

Thanks Ralf. I implemented this manual method and rebased. Let's see if tests pass this time.

@GaelVaroquaux

It seems to me the this commit does nothing more than catching and ignoring a warning. Are warnings raised as errors in the numpy test suite?

Owner

Good questions. Yes, as explained in http://old.nabble.com/Should-abs(-nan-)-be-supported--td34389839.html, the warnings are errors in master, but suppressed in the release branch. That way, the release branch doesn't have any failures due to this, but the master has. On that thread, the conclusion I think was to simply go to the offending test and catch the error.

@certik
Owner

I forgot to merge this. All tests pass and the PR was reviewed.

@certik certik merged commit 7b75899 into numpy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 15, 2012
  1. @certik

    TST: Catch possible warnings

    certik authored
    Previously the test sometimes fails with the following error:
    
    ======================================================================
    ERROR: Test a special case for var
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/travis/virtualenv/python3.2/lib/python3.2/site-packages/numpy/ma/tests/test_core.py", line 2731, in test_varstd_specialcases
        _ = method(out=mout)
      File "/home/travis/virtualenv/python3.2/lib/python3.2/site-packages/numpy/ma/core.py", line 4778, in std
        np.power(out, 0.5, out=out, casting='unsafe')
    RuntimeWarning: invalid value encountered in power
    
    ----------------------------------------------------------------------
    
    Now we catch it, as recommended by the thread:
    
    http://old.nabble.com/Should-abs(-nan-)-be-supported--td34389839.html
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 2 deletions.
  1. +14 −2 numpy/ma/tests/test_core.py
View
16 numpy/ma/tests/test_core.py
@@ -2728,11 +2728,23 @@ def test_varstd_specialcases(self):
self.assertTrue(method(0) is masked)
self.assertTrue(method(-1) is masked)
# Using a masked array as explicit output
- _ = method(out=mout)
+ warn_ctx = WarningManager()
+ warn_ctx.__enter__()
+ try:
+ warnings.simplefilter('ignore')
+ _ = method(out=mout)
+ finally:
+ warn_ctx.__exit__()
self.assertTrue(mout is not masked)
assert_equal(mout.mask, True)
# Using a ndarray as explicit output
- _ = method(out=nout)
+ warn_ctx = WarningManager()
+ warn_ctx.__enter__()
+ try:
+ warnings.simplefilter('ignore')
+ _ = method(out=nout)
+ finally:
+ warn_ctx.__exit__()
self.assertTrue(np.isnan(nout))
#
x = array(arange(10), mask=True)
Something went wrong with that request. Please try again.