Skip to content

Commit

Permalink
Merge pull request #25119 from charris/backport-25090
Browse files Browse the repository at this point in the history
BUG: Make n a long int for np.random.multinomial
  • Loading branch information
charris authored Nov 11, 2023
2 parents 9887c9c + 12b7b35 commit ae77d67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/random/mtrand.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4253,7 +4253,7 @@ cdef class RandomState:
x.shape = tuple(final_shape)
return x

def multinomial(self, np.npy_intp n, object pvals, size=None):
def multinomial(self, long n, object pvals, size=None):
"""
multinomial(n, pvals, size=None)
Expand Down
3 changes: 3 additions & 0 deletions numpy/random/tests/test_randomstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def test_multinomial_pvals_float32(self):
with pytest.raises(ValueError, match=match):
random.multinomial(1, pvals)

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

class TestSetState:
def setup_method(self):
Expand Down

0 comments on commit ae77d67

Please sign in to comment.