Skip to content

Commit

Permalink
TST: Catch possible warnings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
certik committed Nov 15, 2012
1 parent 3418ffc commit 2d841a8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions numpy/ma/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2d841a8

Please sign in to comment.