Skip to content

Commit 156cd42

Browse files
committed
ENH: Finish hypergeometric 0
Add changes to alow hypergeometric 0 Small syncs and cleanups Move legacy_distributions.pxd to legacy folder can be deleted
1 parent 5b8eb72 commit 156cd42

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

numpy/random/generator.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ cdef class RandomGenerator:
115115

116116
def __reduce__(self):
117117
from ._pickle import __generator_ctor
118-
return (__generator_ctor,
119-
(self.brng.state['brng'],),
120-
self.brng.state)
118+
return __generator_ctor, (self.brng.state['brng'],), self.brng.state
121119

122120
def random_sample(self, size=None, dtype=np.float64, out=None):
123121
"""
@@ -3323,7 +3321,7 @@ cdef class RandomGenerator:
33233321
nbad : int or array_like of ints
33243322
Number of ways to make a bad selection. Must be nonnegative.
33253323
nsample : int or array_like of ints
3326-
Number of items sampled. Must be at least 1 and at most
3324+
Number of items sampled. Must be nonnegative and less than
33273325
``ngood + nbad``.
33283326
size : int or tuple of ints, optional
33293327
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
@@ -3415,14 +3413,14 @@ cdef class RandomGenerator:
34153413
return disc(&random_hypergeometric, self._brng, size, self.lock, 0, 3,
34163414
lngood, 'ngood', CONS_NON_NEGATIVE,
34173415
lnbad, 'nbad', CONS_NON_NEGATIVE,
3418-
lnsample, 'nsample', CONS_GTE_1)
3416+
lnsample, 'nsample', CONS_NON_NEGATIVE)
34193417

34203418
if np.any(np.less(np.add(ongood, onbad), onsample)):
34213419
raise ValueError("ngood + nbad < nsample")
34223420
return discrete_broadcast_iii(&random_hypergeometric, self._brng, size, self.lock,
34233421
ongood, 'ngood', CONS_NON_NEGATIVE,
34243422
onbad, 'nbad', CONS_NON_NEGATIVE,
3425-
onsample, 'nsample', CONS_GTE_1)
3423+
onsample, 'nsample', CONS_NON_NEGATIVE)
34263424

34273425
def logseries(self, p, size=None):
34283426
"""

numpy/random/legacy/legacy_distributions.pxd renamed to numpy/random/legacy_distributions.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from libc.stdint cimport uint64_t
55
import numpy as np
66
cimport numpy as np
77

8-
from ..distributions cimport brng_t
8+
from .distributions cimport brng_t
99

1010
cdef extern from "../src/legacy/distributions-boxmuller.h":
1111

numpy/random/mtrand.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from .bounded_integers cimport *
1515
from .bounded_integers import _randint_types
1616
from .common cimport *
1717
from .distributions cimport *
18-
from .legacy.legacy_distributions cimport *
18+
from .legacy_distributions cimport *
1919
from .mt19937 import MT19937 as _MT19937
2020

2121
np.import_array()
@@ -113,9 +113,7 @@ cdef class RandomState:
113113
def __reduce__(self):
114114
state = self.get_state(legacy=False)
115115
from ._pickle import __randomstate_ctor
116-
return (__randomstate_ctor,
117-
(state['brng'],),
118-
state)
116+
return __randomstate_ctor, (state['brng'],), state
119117

120118
cdef _reset_gauss(self):
121119
self._aug_state.has_gauss = 0

numpy/random/tests/test_generator_mt19937.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ def test_hypergeometric(self):
18371837
nsample = [2]
18381838
bad_ngood = [-1]
18391839
bad_nbad = [-2]
1840-
bad_nsample_one = [0]
1840+
bad_nsample_one = [-1]
18411841
bad_nsample_two = [4]
18421842
hypergeom = random.hypergeometric
18431843
desired = np.array([1, 1, 1])
@@ -1868,7 +1868,7 @@ def test_hypergeometric(self):
18681868

18691869
assert_raises(ValueError, hypergeom, -1, 10, 20)
18701870
assert_raises(ValueError, hypergeom, 10, -1, 20)
1871-
assert_raises(ValueError, hypergeom, 10, 10, 0)
1871+
assert_raises(ValueError, hypergeom, 10, 10, -1)
18721872
assert_raises(ValueError, hypergeom, 10, 10, 25)
18731873

18741874
def test_logseries(self):

0 commit comments

Comments
 (0)