Skip to content

Commit 12b7b35

Browse files
thalassemiacharris
authored andcommitted
BUG: Make n a long int for np.random.multinomial
1 parent 249b5be commit 12b7b35

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

numpy/random/mtrand.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4253,7 +4253,7 @@ cdef class RandomState:
42534253
x.shape = tuple(final_shape)
42544254
return x
42554255

4256-
def multinomial(self, np.npy_intp n, object pvals, size=None):
4256+
def multinomial(self, long n, object pvals, size=None):
42574257
"""
42584258
multinomial(n, pvals, size=None)
42594259

numpy/random/tests/test_randomstate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ def test_multinomial_pvals_float32(self):
183183
with pytest.raises(ValueError, match=match):
184184
random.multinomial(1, pvals)
185185

186+
def test_multinomial_n_float(self):
187+
# Non-index integer types should gracefully truncate floats
188+
random.multinomial(100.5, [0.2, 0.8])
186189

187190
class TestSetState:
188191
def setup_method(self):

0 commit comments

Comments
 (0)