Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dtype of np.random.choice differs with presence of p on windows #9867

Closed
jcrist opened this issue Oct 16, 2017 · 4 comments · Fixed by #13695
Closed

dtype of np.random.choice differs with presence of p on windows #9867

jcrist opened this issue Oct 16, 2017 · 4 comments · Fixed by #13695

Comments

@jcrist
Copy link
Contributor

jcrist commented Oct 16, 2017

The dtype of the output of np.random.choice with a scalar a is different if p is provided on windows:

>>> import numpy as np
>>> p = np.array([0.5, 0.5])
>>> np.random.choice(2, size=1).dtype
dtype('int32')
>>> np.random.choice(2, p=p, size=1).dtype
dtype('int64')
>>> np.__version__
1.13.1

I'd expect the output dtype to be consistent whether p is present or absent. Since the dtype of arange on win32 is int32, the int64 dtype output is probably the incorrect one.

@bashtage
Copy link
Contributor

This difference occurs at

https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/mtrand.pyx#L1155

since searchsorted returns int64 irrespective of platform.

@bashtage
Copy link
Contributor

bashtage commented Oct 18, 2017

The return type for searchsorted is NPY_INTP here:

ret = (PyArrayObject *)PyArray_New(&PyArray_Type, PyArray_NDIM(ap2),

bashtage added a commit to bashtage/randomgen that referenced this issue Apr 12, 2019
Ensure that choice uses int64 for all paths/platforms

xref numpy/numpy#9867
bashtage added a commit to bashtage/randomgen that referenced this issue Apr 12, 2019
Ensure that choice uses int64 for all paths/platforms

xref numpy/numpy#9867
@bashtage
Copy link
Contributor

bashtage commented Jun 1, 2019

@mattip This is fixed in Generator but not in RandomState. Should it be fixed in RandomState or left as it was in 1.16?

@mattip
Copy link
Member

mattip commented Jun 1, 2019

I guess this is a bug, and should be fixed, unless it breaks something else.

bashtage added a commit to bashtage/numpy that referenced this issue Jun 1, 2019
Downcast from searchsorted on Windows to ensure int32 is returned

closes numpy#9867
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants