summaryrefslogtreecommitdiff
path: root/numpy/random/tests/test_random.py
diff options
context:
space:
mode:
authorSimon Gibbons <simongibbons@gmail.com>2017-04-01 21:59:53 +0100
committerSimon Gibbons <simongibbons@gmail.com>2017-04-01 22:54:09 +0100
commita6c3d0eeab3d65b3ec047e8601da84a2ebb97d70 (patch)
tree3b3b4a36bd4c439cdce7e02c6ebc49fe34a3deb9 /numpy/random/tests/test_random.py
parentc93201acabd010bcd15464d058faa02da207a292 (diff)
downloadnumpy-a6c3d0eeab3d65b3ec047e8601da84a2ebb97d70.tar.gz
BUG: Ensure Errors are correctly checked when PyFloat_AsDouble is called.
There was an error in np.random.uniform where if np.random.uniform were called with a type that throwed exceptions when it was converted to a float this exception wouldn't be raised. This bug was due to an issue where PyFloat_AsDouble was called but no check for PyErr_Occurred was performed after. This PR fixes the issue by ensuring that Cython will always emit a call to PyErr_Occurred if PyFloat_AsDouble returns -1.0 Fixes: #8865
Diffstat (limited to 'numpy/random/tests/test_random.py')
-rw-r--r--numpy/random/tests/test_random.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 09ed5bb54..cb2afa9f3 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -822,6 +822,20 @@ class TestRandomDist(TestCase):
# DBL_MAX by increasing fmin a bit
np.random.uniform(low=np.nextafter(fmin, 1), high=fmax / 1e17)
+ def test_uniform_propogates_exeptions(self):
+ # Tests that uniform correctly propogates exceptions
+ # when called with a type which throws when converted to
+ # a float
+ #
+ # Regression test for gh: 8865
+
+ class ThrowableType(np.ndarray):
+ def __float__(self):
+ raise ValueError
+
+ x = np.array(1.0).view(ThrowableType)
+ assert_raises(ValueError, np.uniform, x, x)
+
def test_vonmises(self):
np.random.seed(self.seed)
actual = np.random.vonmises(mu=1.23, kappa=1.54, size=(3, 2))