diff options
| author | Warren Weckesser <warren.weckesser@gmail.com> | 2020-04-05 23:25:53 -0400 |
|---|---|---|
| committer | Warren Weckesser <warren.weckesser@gmail.com> | 2020-04-05 23:35:50 -0400 |
| commit | f90f26c40ac4b37e1df8c76ee6745433557d999b (patch) | |
| tree | 57af5f657f9769fdab28eb1dd45dd621c14fa7fe /numpy/random/tests | |
| parent | 0f6a3aaa34fe72586f8c66ecc4744fc960d62ae2 (diff) | |
| download | numpy-f90f26c40ac4b37e1df8c76ee6745433557d999b.tar.gz | |
BUG: random: Disallow p=0 in negative_binomial
Make `Generator.negative_binomial` raise a ValueError if p=0.
`negative_binomial(n, p)` draws samples from the distribution of
the number of failures until n successes are encountered. If p is 0,
then a success is never encountered, so the probability distribution
is 0 for any finite number of failures. In other words, it is not
really a meaningful distribution, so we disallow p=0.
Closes gh-15913.
Diffstat (limited to 'numpy/random/tests')
| -rw-r--r-- | numpy/random/tests/test_generator_mt19937.py | 5 |
1 files changed, 5 insertions, 0 deletions
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)) |
