diff options
-rw-r--r-- | numpy/random/mtrand/Python.pxi | 2 | ||||
-rw-r--r-- | numpy/random/tests/test_random.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/numpy/random/mtrand/Python.pxi b/numpy/random/mtrand/Python.pxi index f23a3bfe6..0571831a6 100644 --- a/numpy/random/mtrand/Python.pxi +++ b/numpy/random/mtrand/Python.pxi @@ -15,7 +15,7 @@ cdef extern from "Python.h": object PyString_FromStringAndSize(char* c_string, int length) # Float API - double PyFloat_AsDouble(object ob) + double PyFloat_AsDouble(object ob) except? -1.0 long PyInt_AsLong(object ob) # Memory API 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)) |