summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2012-03-02 20:24:45 +0100
committerRalf Gommers <ralf.gommers@googlemail.com>2012-03-02 20:25:02 +0100
commitb9872b41422e33c9910829cd54268a510ec9436b (patch)
tree33168c591f5186f521bb1c21ae3de73642d7f0e1
parentba40918d39c8e0c41a6bffac67d2d74dd335161f (diff)
parente962f6b0be32515d6a1d9fb25d24ca250d632a4c (diff)
downloadnumpy-b9872b41422e33c9910829cd54268a510ec9436b.tar.gz
Merge pull request #215 from rgommers/windows-runtime-warnings.
This PR fixes a number of warnings, that were converted to test errors in master. Some of them were only visible with MSVC.
-rw-r--r--numpy/core/tests/test_numeric.py6
-rw-r--r--numpy/core/tests/test_regression.py12
-rw-r--r--numpy/core/tests/test_umath.py47
-rw-r--r--numpy/core/tests/test_umath_complex.py46
-rw-r--r--numpy/lib/tests/test_function_base.py20
-rw-r--r--numpy/lib/tests/test_io.py15
6 files changed, 91 insertions, 55 deletions
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 205bf56c4..de41f0c1f 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -1159,6 +1159,12 @@ class TestAllclose(object):
rtol = 1e-5
atol = 1e-8
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**self.olderr)
+
def tst_allclose(self,x,y):
assert_(allclose(x,y), "%s and %s not close" % (x,y))
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 55d5b6ec6..c03c5b02f 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1003,10 +1003,14 @@ class TestRegression(TestCase):
def test_sign_for_complex_nan(self, level=rlevel):
"""Ticket 794."""
- C = np.array([-np.inf, -2+1j, 0, 2-1j, np.inf, np.nan])
- have = np.sign(C)
- want = np.array([-1+0j, -1+0j, 0+0j, 1+0j, 1+0j, np.nan])
- assert_equal(have, want)
+ olderr = np.seterr(invalid='ignore')
+ try:
+ C = np.array([-np.inf, -2+1j, 0, 2-1j, np.inf, np.nan])
+ have = np.sign(C)
+ want = np.array([-1+0j, -1+0j, 0+0j, 1+0j, 1+0j, np.nan])
+ assert_equal(have, want)
+ finally:
+ np.seterr(**olderr)
def test_for_equal_names(self, level=rlevel):
"""Ticket #674"""
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 3e17b58dc..1ac958be7 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -5,6 +5,14 @@ import numpy.core.umath as ncu
import numpy as np
+class _FilterInvalids():
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**self.olderr)
+
+
class TestDivision(TestCase):
def test_division_int(self):
# int division should follow Python
@@ -152,7 +160,7 @@ class TestExp2(TestCase):
assert_almost_equal(np.exp2(yf), xf)
-class TestLogAddExp2(object):
+class TestLogAddExp2(object, _FilterInvalids):
# Need test for intermediate precisions
def test_logaddexp2_values(self) :
x = [1, 2, 3, 4, 5]
@@ -219,7 +227,7 @@ class TestExp(TestCase):
assert_almost_equal(np.exp(yf), xf)
-class TestLogAddExp(object):
+class TestLogAddExp(object, _FilterInvalids):
def test_logaddexp_values(self) :
x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]
@@ -432,7 +440,7 @@ class TestLdexp(TestCase):
np.seterr(**err)
-class TestMaximum(TestCase):
+class TestMaximum(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -479,7 +487,7 @@ class TestMaximum(TestCase):
assert_equal(np.maximum(arg1, arg2), arg2)
-class TestMinimum(TestCase):
+class TestMinimum(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -526,7 +534,7 @@ class TestMinimum(TestCase):
assert_equal(np.minimum(arg1, arg2), arg1)
-class TestFmax(TestCase):
+class TestFmax(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -568,7 +576,7 @@ class TestFmax(TestCase):
assert_equal(np.fmax(arg1, arg2), out)
-class TestFmin(TestCase):
+class TestFmin(object, _FilterInvalids):
def test_reduce(self):
dflt = np.typecodes['AllFloat']
dint = np.typecodes['AllInteger']
@@ -1217,19 +1225,24 @@ def test_complex_nan_comparisons():
fins = [complex(1, 0), complex(-1, 0), complex(0, 1), complex(0, -1),
complex(1, 1), complex(-1, -1), complex(0, 0)]
- for x in nans + fins:
- x = np.array([x])
- for y in nans + fins:
- y = np.array([y])
+ olderr = np.seterr(invalid='ignore')
+ try:
+ for x in nans + fins:
+ x = np.array([x])
+ for y in nans + fins:
+ y = np.array([y])
+
+ if np.isfinite(x) and np.isfinite(y):
+ continue
- if np.isfinite(x) and np.isfinite(y):
- continue
+ assert_equal(x < y, False, err_msg="%r < %r" % (x, y))
+ assert_equal(x > y, False, err_msg="%r > %r" % (x, y))
+ assert_equal(x <= y, False, err_msg="%r <= %r" % (x, y))
+ assert_equal(x >= y, False, err_msg="%r >= %r" % (x, y))
+ assert_equal(x == y, False, err_msg="%r == %r" % (x, y))
+ finally:
+ np.seterr(**olderr)
- assert_equal(x < y, False, err_msg="%r < %r" % (x, y))
- assert_equal(x > y, False, err_msg="%r > %r" % (x, y))
- assert_equal(x <= y, False, err_msg="%r <= %r" % (x, y))
- assert_equal(x >= y, False, err_msg="%r >= %r" % (x, y))
- assert_equal(x == y, False, err_msg="%r == %r" % (x, y))
if __name__ == "__main__":
run_module_suite()
diff --git a/numpy/core/tests/test_umath_complex.py b/numpy/core/tests/test_umath_complex.py
index 4fe0faa59..76fa29be8 100644
--- a/numpy/core/tests/test_umath_complex.py
+++ b/numpy/core/tests/test_umath_complex.py
@@ -12,7 +12,7 @@ import numpy as np
# At least on Windows the results of many complex functions are not conforming
# to the C99 standard. See ticket 1574.
# Ditto for Solaris (ticket 1642) and OS X on PowerPC.
-olderr = np.seterr(divide='ignore')
+olderr = np.seterr(all='ignore')
try:
functions_seem_flaky = ((np.exp(complex(np.inf, 0)).imag != 0)
or (np.log(complex(np.NZERO, 0)).imag != np.pi))
@@ -381,16 +381,18 @@ class TestCsqrt(object):
# cuts first)
class TestCpow(TestCase):
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**self.olderr)
+
def test_simple(self):
x = np.array([1+1j, 0+2j, 1+2j, np.inf, np.nan])
- err = np.seterr(invalid='ignore')
- try:
- y_r = x ** 2
- y = np.power(x, 2)
- for i in range(len(x)):
- assert_almost_equal(y[i], y_r[i])
- finally:
- np.seterr(**err)
+ y_r = x ** 2
+ y = np.power(x, 2)
+ for i in range(len(x)):
+ assert_almost_equal(y[i], y_r[i])
def test_scalar(self):
x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan])
@@ -401,13 +403,9 @@ class TestCpow(TestCase):
# Substitute a result allowed by C99 standard
p_r[4] = complex(np.inf, np.nan)
# Do the same with numpy complex scalars
- err = np.seterr(invalid='ignore')
- try:
- n_r = [x[i] ** y[i] for i in lx]
- for i in lx:
- assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
- finally:
- np.seterr(**err)
+ n_r = [x[i] ** y[i] for i in lx]
+ for i in lx:
+ assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
def test_array(self):
x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan])
@@ -418,15 +416,17 @@ class TestCpow(TestCase):
# Substitute a result allowed by C99 standard
p_r[4] = complex(np.inf, np.nan)
# Do the same with numpy arrays
- err = np.seterr(invalid='ignore')
- try:
- n_r = x ** y
- for i in lx:
- assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
- finally:
- np.seterr(**err)
+ n_r = x ** y
+ for i in lx:
+ assert_almost_equal(n_r[i], p_r[i], err_msg='Loop %d\n' % i)
class TestCabs(object):
+ def setUp(self):
+ self.olderr = np.seterr(invalid='ignore')
+
+ def tearDown(self):
+ np.seterr(**self.olderr)
+
def test_simple(self):
x = np.array([1+1j, 0+2j, 1+2j, np.inf, np.nan])
y_r = np.array([np.sqrt(2.), 2, np.sqrt(5), np.inf, np.nan])
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index fc033b164..a7d501c52 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -784,14 +784,18 @@ class TestHistogramdd(TestCase):
def test_inf_edges(self):
"""Test using +/-inf bin edges works. See #1788."""
- x = np.arange(6).reshape(3, 2)
- expected = np.array([[1, 0], [0, 1], [0, 1]])
- h, e = np.histogramdd(x, bins=[3, [-np.inf, 2, 10]])
- assert_allclose(h, expected)
- h, e = np.histogramdd(x, bins=[3, np.array([-1, 2, np.inf])])
- assert_allclose(h, expected)
- h, e = np.histogramdd(x, bins=[3, [-np.inf, 3, np.inf]])
- assert_allclose(h, expected)
+ olderr = np.seterr(invalid='ignore')
+ try:
+ x = np.arange(6).reshape(3, 2)
+ expected = np.array([[1, 0], [0, 1], [0, 1]])
+ h, e = np.histogramdd(x, bins=[3, [-np.inf, 2, 10]])
+ assert_allclose(h, expected)
+ h, e = np.histogramdd(x, bins=[3, np.array([-1, 2, np.inf])])
+ assert_allclose(h, expected)
+ h, e = np.histogramdd(x, bins=[3, [-np.inf, 3, np.inf]])
+ assert_allclose(h, expected)
+ finally:
+ np.seterr(**olderr)
class TestUnique(TestCase):
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 949d8fb45..41a95de10 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -586,9 +586,18 @@ class TestLoadTxt(TestCase):
e.seek(0)
x = np.loadtxt(e, dtype=int, delimiter=',', ndmin=0)
assert_(x.shape == (3,))
- f = StringIO()
- assert_(np.loadtxt(f, ndmin=2).shape == (0, 1,))
- assert_(np.loadtxt(f, ndmin=1).shape == (0,))
+
+ # Test ndmin kw with empty file.
+ warn_ctx = WarningManager()
+ warn_ctx.__enter__()
+ try:
+ warnings.filterwarnings("ignore",
+ message="loadtxt: Empty input file:")
+ f = StringIO()
+ assert_(np.loadtxt(f, ndmin=2).shape == (0, 1,))
+ assert_(np.loadtxt(f, ndmin=1).shape == (0,))
+ finally:
+ warn_ctx.__exit__()
def test_generator_source(self):
def count():