summaryrefslogtreecommitdiff
path: root/numpy/random
diff options
context:
space:
mode:
authorAlistair Muldal <alimuldal@gmail.com>2016-10-30 20:04:59 +0000
committerAlistair Muldal <alimuldal@gmail.com>2016-11-02 23:29:04 +0000
commitf5bb42f0b02fa954f03bf4d96801877a4837c8cb (patch)
tree88783e64b4e36240a0dc5ac773a430ae6476c4a4 /numpy/random
parent6ae842001332f532e0c76815d49336ecc2b88dde (diff)
downloadnumpy-f5bb42f0b02fa954f03bf4d96801877a4837c8cb.tar.gz
BUG: Better check for invalid bounds in np.random.uniform.
Also check for invalid bounds when low= and high= are arraylike rather than scalar (closes #8226)
Diffstat (limited to 'numpy/random')
-rw-r--r--numpy/random/mtrand/mtrand.pyx4
-rw-r--r--numpy/random/tests/test_random.py2
2 files changed, 6 insertions, 0 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index 127e52d5e..922ca7993 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -1295,6 +1295,10 @@ cdef class RandomState:
Py_INCREF(temp) # needed to get around Pyrex's automatic reference-counting
# rules because EnsureArray steals a reference
odiff = <ndarray>PyArray_EnsureArray(temp)
+
+ if not np.all(np.isfinite(odiff)):
+ raise OverflowError('Range exceeds valid bounds')
+
return cont2_array(self.internal_state, rk_uniform, size, olow, odiff,
self.lock)
diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py
index 012bf4826..47301a770 100644
--- a/numpy/random/tests/test_random.py
+++ b/numpy/random/tests/test_random.py
@@ -809,6 +809,8 @@ class TestRandomDist(TestCase):
assert_raises(OverflowError, func, -np.inf, 0)
assert_raises(OverflowError, func, 0, np.inf)
assert_raises(OverflowError, func, fmin, fmax)
+ assert_raises(OverflowError, func, [-np.inf], [0])
+ assert_raises(OverflowError, func, [0], [np.inf])
# (fmax / 1e17) - fmin is within range, so this should not throw
np.random.uniform(low=fmin, high=fmax / 1e17)