diff --git a/numpy/random/generator.pyx b/numpy/random/generator.pyx index 6fa24b967856..fed978e70a9a 100644 --- a/numpy/random/generator.pyx +++ b/numpy/random/generator.pyx @@ -115,9 +115,7 @@ cdef class RandomGenerator: def __reduce__(self): from ._pickle import __generator_ctor - return (__generator_ctor, - (self.brng.state['brng'],), - self.brng.state) + return __generator_ctor, (self.brng.state['brng'],), self.brng.state def random_sample(self, size=None, dtype=np.float64, out=None): """ @@ -3323,7 +3321,7 @@ cdef class RandomGenerator: nbad : int or array_like of ints Number of ways to make a bad selection. Must be nonnegative. nsample : int or array_like of ints - Number of items sampled. Must be at least 1 and at most + Number of items sampled. Must be nonnegative and less than ``ngood + nbad``. size : int or tuple of ints, optional Output shape. If the given shape is, e.g., ``(m, n, k)``, then @@ -3415,14 +3413,14 @@ cdef class RandomGenerator: return disc(&random_hypergeometric, self._brng, size, self.lock, 0, 3, lngood, 'ngood', CONS_NON_NEGATIVE, lnbad, 'nbad', CONS_NON_NEGATIVE, - lnsample, 'nsample', CONS_GTE_1) + lnsample, 'nsample', CONS_NON_NEGATIVE) if np.any(np.less(np.add(ongood, onbad), onsample)): raise ValueError("ngood + nbad < nsample") return discrete_broadcast_iii(&random_hypergeometric, self._brng, size, self.lock, ongood, 'ngood', CONS_NON_NEGATIVE, onbad, 'nbad', CONS_NON_NEGATIVE, - onsample, 'nsample', CONS_GTE_1) + onsample, 'nsample', CONS_NON_NEGATIVE) def logseries(self, p, size=None): """ diff --git a/numpy/random/legacy/legacy_distributions.pxd b/numpy/random/legacy_distributions.pxd similarity index 98% rename from numpy/random/legacy/legacy_distributions.pxd rename to numpy/random/legacy_distributions.pxd index bc00994dbacb..08dde3315c34 100644 --- a/numpy/random/legacy/legacy_distributions.pxd +++ b/numpy/random/legacy_distributions.pxd @@ -5,7 +5,7 @@ from libc.stdint cimport uint64_t import numpy as np cimport numpy as np -from ..distributions cimport brng_t +from .distributions cimport brng_t cdef extern from "../src/legacy/distributions-boxmuller.h": diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index 2d3ea32cba5a..3f73981cd918 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -15,7 +15,7 @@ from .bounded_integers cimport * from .bounded_integers import _randint_types from .common cimport * from .distributions cimport * -from .legacy.legacy_distributions cimport * +from .legacy_distributions cimport * from .mt19937 import MT19937 as _MT19937 np.import_array() @@ -113,9 +113,7 @@ cdef class RandomState: def __reduce__(self): state = self.get_state(legacy=False) from ._pickle import __randomstate_ctor - return (__randomstate_ctor, - (state['brng'],), - state) + return __randomstate_ctor, (state['brng'],), state cdef _reset_gauss(self): self._aug_state.has_gauss = 0 diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py index d591ca3399e9..ff5dc01504df 100644 --- a/numpy/random/tests/test_generator_mt19937.py +++ b/numpy/random/tests/test_generator_mt19937.py @@ -1837,7 +1837,7 @@ def test_hypergeometric(self): nsample = [2] bad_ngood = [-1] bad_nbad = [-2] - bad_nsample_one = [0] + bad_nsample_one = [-1] bad_nsample_two = [4] hypergeom = random.hypergeometric desired = np.array([1, 1, 1]) @@ -1868,7 +1868,7 @@ def test_hypergeometric(self): assert_raises(ValueError, hypergeom, -1, 10, 20) assert_raises(ValueError, hypergeom, 10, -1, 20) - assert_raises(ValueError, hypergeom, 10, 10, 0) + assert_raises(ValueError, hypergeom, 10, 10, -1) assert_raises(ValueError, hypergeom, 10, 10, 25) def test_logseries(self):