Skip to content

Commit 580c7c8

Browse files
authored
Merge pull request #90 from bashtage/catchup-numpy-changes
TST: Add upstream test changes
2 parents 8708a2a + d067ca5 commit 580c7c8

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

randomstate/cython_overrides.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cdef extern from "Python.h":
2-
double PyFloat_AsDouble(object ob)
3-
long PyInt_AsLong(object ob)
2+
double PyFloat_AsDouble(object ob) except? -1.0
3+
long PyInt_AsLong(object ob) except? -1
44
int PyErr_Occurred()
55
void PyErr_Clear()

randomstate/tests/test_numpy_mt19937.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
TestCase, run_module_suite, assert_, assert_raises, assert_equal,
66
assert_warns, assert_no_warnings, assert_array_equal,
77
assert_array_almost_equal)
8-
from numpy.compat import asbytes
98
import sys
109
import warnings
1110
import randomstate as random
@@ -394,7 +393,7 @@ def test_choice_return_shape(self):
394393
def test_bytes(self):
395394
mt19937.seed(self.seed)
396395
actual = mt19937.bytes(10)
397-
desired = asbytes('\x82Ui\x9e\xff\x97+Wf\xa5')
396+
desired = b'\x82Ui\x9e\xff\x97+Wf\xa5'
398397
assert_equal(actual, desired)
399398

400399
def test_shuffle(self):
@@ -824,6 +823,27 @@ def test_uniform_range_bounds(self):
824823
# DBL_MAX by increasing fmin a bit
825824
mt19937.uniform(low=np.nextafter(fmin, 1), high=fmax / 1e17)
826825

826+
def test_scalar_exception_propagation(self):
827+
# Tests that exceptions are correctly propagated in distributions
828+
# when called with objects that throw exceptions when converted to
829+
# scalars.
830+
#
831+
# Regression test for gh: 8865
832+
833+
class ThrowingFloat(np.ndarray):
834+
def __float__(self):
835+
raise TypeError
836+
837+
throwing_float = np.array(1.0).view(ThrowingFloat)
838+
assert_raises(TypeError, mt19937.uniform, throwing_float, throwing_float)
839+
840+
class ThrowingInteger(np.ndarray):
841+
def __int__(self):
842+
raise TypeError
843+
844+
throwing_int = np.array(1).view(ThrowingInteger)
845+
assert_raises(TypeError, mt19937.hypergeometric, throwing_int, 1, 1)
846+
827847
def test_vonmises(self):
828848
mt19937.seed(self.seed)
829849
actual = mt19937.vonmises(mu=1.23, kappa=1.54, size=(3, 2))

0 commit comments

Comments
 (0)