Skip to content

Commit

Permalink
Merge pull request #90 from bashtage/catchup-numpy-changes
Browse files Browse the repository at this point in the history
TST: Add upstream test changes
  • Loading branch information
bashtage committed Apr 3, 2017
2 parents 8708a2a + d067ca5 commit 580c7c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions randomstate/cython_overrides.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cdef extern from "Python.h":
double PyFloat_AsDouble(object ob)
long PyInt_AsLong(object ob)
double PyFloat_AsDouble(object ob) except? -1.0
long PyInt_AsLong(object ob) except? -1
int PyErr_Occurred()
void PyErr_Clear()
24 changes: 22 additions & 2 deletions randomstate/tests/test_numpy_mt19937.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
TestCase, run_module_suite, assert_, assert_raises, assert_equal,
assert_warns, assert_no_warnings, assert_array_equal,
assert_array_almost_equal)
from numpy.compat import asbytes
import sys
import warnings
import randomstate as random
Expand Down Expand Up @@ -394,7 +393,7 @@ def test_choice_return_shape(self):
def test_bytes(self):
mt19937.seed(self.seed)
actual = mt19937.bytes(10)
desired = asbytes('\x82Ui\x9e\xff\x97+Wf\xa5')
desired = b'\x82Ui\x9e\xff\x97+Wf\xa5'
assert_equal(actual, desired)

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

def test_scalar_exception_propagation(self):
# Tests that exceptions are correctly propagated in distributions
# when called with objects that throw exceptions when converted to
# scalars.
#
# Regression test for gh: 8865

class ThrowingFloat(np.ndarray):
def __float__(self):
raise TypeError

throwing_float = np.array(1.0).view(ThrowingFloat)
assert_raises(TypeError, mt19937.uniform, throwing_float, throwing_float)

class ThrowingInteger(np.ndarray):
def __int__(self):
raise TypeError

throwing_int = np.array(1).view(ThrowingInteger)
assert_raises(TypeError, mt19937.hypergeometric, throwing_int, 1, 1)

def test_vonmises(self):
mt19937.seed(self.seed)
actual = mt19937.vonmises(mu=1.23, kappa=1.54, size=(3, 2))
Expand Down

0 comments on commit 580c7c8

Please sign in to comment.