diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-04-07 22:43:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-07 22:43:31 +0300 |
commit | 0ce156413feb21a4f2a8eae3b1cd954d04240edd (patch) | |
tree | 57af5f657f9769fdab28eb1dd45dd621c14fa7fe /numpy/random | |
parent | 0f6a3aaa34fe72586f8c66ecc4744fc960d62ae2 (diff) | |
parent | f90f26c40ac4b37e1df8c76ee6745433557d999b (diff) | |
download | numpy-0ce156413feb21a4f2a8eae3b1cd954d04240edd.tar.gz |
Merge pull request #15914 from WarrenWeckesser/negbin-pgt0
BUG: random: Disallow p=0 in negative_binomial
Diffstat (limited to 'numpy/random')
-rw-r--r-- | numpy/random/_generator.pyx | 6 | ||||
-rw-r--r-- | numpy/random/tests/test_generator_mt19937.py | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx index 6b8a2f70b..27e006cc3 100644 --- a/numpy/random/_generator.pyx +++ b/numpy/random/_generator.pyx @@ -2844,14 +2844,14 @@ cdef class Generator: Samples are drawn from a negative binomial distribution with specified parameters, `n` successes and `p` probability of success where `n` - is > 0 and `p` is in the interval [0, 1]. + is > 0 and `p` is in the interval (0, 1]. Parameters ---------- n : float or array_like of floats Parameter of the distribution, > 0. p : float or array_like of floats - Parameter of the distribution, >= 0 and <=1. + Parameter of the distribution. Must satisfy 0 < p <= 1. size : int or tuple of ints, optional Output shape. If the given shape is, e.g., ``(m, n, k)``, then ``m * n * k`` samples are drawn. If size is ``None`` (default), @@ -2909,7 +2909,7 @@ cdef class Generator: """ return disc(&random_negative_binomial, &self._bitgen, size, self.lock, 2, 0, n, 'n', CONS_POSITIVE_NOT_NAN, - p, 'p', CONS_BOUNDED_0_1, + p, 'p', CONS_BOUNDED_GT_0_1, 0.0, '', CONS_NONE) def poisson(self, lam=1.0, size=None): diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py index b10c1310e..c4c1fa316 100644 --- a/numpy/random/tests/test_generator_mt19937.py +++ b/numpy/random/tests/test_generator_mt19937.py @@ -1297,6 +1297,11 @@ class TestRandomDist: assert_raises(ValueError, random.negative_binomial, 100, [np.nan] * 10) + def test_negative_binomial_p0_exception(self): + # Verify that p=0 raises an exception. + with assert_raises(ValueError): + x = random.negative_binomial(1, 0) + def test_noncentral_chisquare(self): random = Generator(MT19937(self.seed)) actual = random.noncentral_chisquare(df=5, nonc=5, size=(3, 2)) |