diff --git a/quantecon/random/tests/test_utilities.py b/quantecon/random/tests/test_utilities.py index 30020a907..ca1fc482b 100644 --- a/quantecon/random/tests/test_utilities.py +++ b/quantecon/random/tests/test_utilities.py @@ -125,6 +125,17 @@ def test_return_types(self): out = func(self.cdf, size) assert_(out.shape == (size,)) + def test_numpy_integer_size(self): + """ + A numpy integer `size` must request an array, as a Python `int` + does and as the jitted path already did. See #918. + + """ + size = np.int64(10) + for func in self.draw_funcs: + out = func(self.cdf, size) + assert_(out.shape == (size,)) + def test_return_values(self): for func in self.draw_funcs: out = func(self.cdf) diff --git a/quantecon/random/utilities.py b/quantecon/random/utilities.py index 9ca73ecef..d3982f30f 100644 --- a/quantecon/random/utilities.py +++ b/quantecon/random/utilities.py @@ -246,7 +246,10 @@ def draw(cdf, size=None, rng=None): """ if rng is None: rng = np.random - if isinstance(size, int): + # `bool` subclasses `int` in Python but Numba types it as `Boolean`, + # not `Integer`, so the exclusion keeps this branch in step with the + # `@overload` implementation below. See #918. + if isinstance(size, (int, np.integer)) and not isinstance(size, bool): rs = rng.random(size) out = np.searchsorted(cdf, rs, side='right') return out