diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2022-11-15 13:31:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 13:31:47 -0600 |
commit | 3ca02ce5b1a4ec2412cad839d42452a4200a5270 (patch) | |
tree | f1777b8defeb5c33bafadf89da770ab14358c0b3 /numpy/random/tests/test_generator_mt19937.py | |
parent | 8cededdf4eeebd4f1985bd74c11fbf44f367937f (diff) | |
parent | e88592e94a0b7de726bc1e3dbf3abf637be47273 (diff) | |
download | numpy-3ca02ce5b1a4ec2412cad839d42452a4200a5270.tar.gz |
Merge pull request #22594 from charris/backport-22450
BUG: Fix boundschecking for `random.logseries`
Diffstat (limited to 'numpy/random/tests/test_generator_mt19937.py')
-rw-r--r-- | numpy/random/tests/test_generator_mt19937.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py index b550cd508..73d915e02 100644 --- a/numpy/random/tests/test_generator_mt19937.py +++ b/numpy/random/tests/test_generator_mt19937.py @@ -1363,10 +1363,22 @@ class TestRandomDist: [5, 1]]) assert_array_equal(actual, desired) - def test_logseries_exceptions(self): - with np.errstate(invalid='ignore'): - assert_raises(ValueError, random.logseries, np.nan) - assert_raises(ValueError, random.logseries, [np.nan] * 10) + def test_logseries_zero(self): + random = Generator(MT19937(self.seed)) + assert random.logseries(0) == 1 + + @pytest.mark.parametrize("value", [np.nextafter(0., -1), 1., np.nan, 5.]) + def test_logseries_exceptions(self, value): + random = Generator(MT19937(self.seed)) + with np.errstate(invalid="ignore"): + with pytest.raises(ValueError): + random.logseries(value) + with pytest.raises(ValueError): + # contiguous path: + random.logseries(np.array([value] * 10)) + with pytest.raises(ValueError): + # non-contiguous path: + random.logseries(np.array([value] * 10)[::2]) def test_multinomial(self): random = Generator(MT19937(self.seed)) |