Skip to content
This repository

TST: Catch possible warnings #2745

Merged
merged 1 commit into from over 1 year ago

3 participants

Ondřej Čertík Ralf Gommers Gael Varoquaux
Ondřej Čertík
Collaborator

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

Ondřej Čertík
Collaborator

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

Ralf Gommers
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__()
Ondřej Čertík 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
Ondřej Čertík
Collaborator

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

Gael Varoquaux

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?

Collaborator

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.

Ondřej Čertík
Collaborator

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

Ondřej Čertík certik merged commit 7b75899 into from December 03, 2012
Ondřej Čertík certik closed this December 03, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 14, 2012
Ondřej Čertík 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 14 additions and 2 deletions. Show diff stats Hide diff stats

  1. 16  numpy/ma/tests/test_core.py
16  numpy/ma/tests/test_core.py
@@ -2728,11 +2728,23 @@ def test_varstd_specialcases(self):
2728 2728
             self.assertTrue(method(0) is masked)
2729 2729
             self.assertTrue(method(-1) is masked)
2730 2730
             # Using a masked array as explicit output
2731  
-            _ = method(out=mout)
  2731
+            warn_ctx = WarningManager()
  2732
+            warn_ctx.__enter__()
  2733
+            try:
  2734
+                warnings.simplefilter('ignore')
  2735
+                _ = method(out=mout)
  2736
+            finally:
  2737
+                warn_ctx.__exit__()
2732 2738
             self.assertTrue(mout is not masked)
2733 2739
             assert_equal(mout.mask, True)
2734 2740
             # Using a ndarray as explicit output
2735  
-            _ = method(out=nout)
  2741
+            warn_ctx = WarningManager()
  2742
+            warn_ctx.__enter__()
  2743
+            try:
  2744
+                warnings.simplefilter('ignore')
  2745
+                _ = method(out=nout)
  2746
+            finally:
  2747
+                warn_ctx.__exit__()
2736 2748
             self.assertTrue(np.isnan(nout))
2737 2749
         #
2738 2750
         x = array(arange(10), mask=True)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.