Skip to content

BUG: Enforce dtype for randint singletons #7254

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

Merged
merged 1 commit into from
Feb 17, 2016
Merged

BUG: Enforce dtype for randint singletons #7254

merged 1 commit into from
Feb 17, 2016

Conversation

gfyoung
Copy link
Contributor

@gfyoung gfyoung commented Feb 15, 2016

Addresses issue in #7203 in which specifying the dtype for a single integer was not being respected. This PR makes the randint API consistent across all size specifications in that only numbers of numpy dtypes are returned, which already occurs when you generate arrays using randint.

@gfyoung
Copy link
Contributor Author

gfyoung commented Feb 15, 2016

@charris : +1 for the Discussion label - I would love to hear other people's opinion about this!

@ahaldane
Copy link
Member

I think it makes sense to return the numpy type if the dtype keyword was specified.

To preserve backwards compatibility with 1.10 we could still return a Python int if neither size nor dtype are specified, I suppose. But that sounds like an extra complication that will almost never affect anyone, and if users know randint returns arrays of np.int64 by default, they will not be surprised to get an np.int64 when size=1 too.

What is the test error you get in diophantine_fuzz? I don't get it on my system after removing the cast to int.

Big kudos to you and @charris by the way for all the improvements to the np.random dtype argument!

@gfyoung
Copy link
Contributor Author

gfyoung commented Feb 15, 2016

@ahaldane : Thank you! Though I think @charris should get extra big kudos since he was the first person to successfully implement it into the codebase 😄

I agree that backwards compatibility need not necessarily be preserved in such a case since I would imagine the most common use case is to generate arrays of data. Also, as the dtype parameter has not even been officially released yet, the impact stands to be minor IMHO.

Regarding the test failures, the tests fail, at least locally, due to warnings about scalar overflow because they're now Numpy integers and not Python integers.

@charris charris added this to the 1.11.0 release milestone Feb 16, 2016
@charris
Copy link
Member

charris commented Feb 16, 2016

Added the 1.11.0 milestone since, if this goes in, we might as well start right :)

@gfyoung
Copy link
Contributor Author

gfyoung commented Feb 17, 2016

Is there anything else people would like to add with regards to this change? Otherwise, it should be good to merge.

@ahaldane
Copy link
Member

I was still a little worried about the unit test you modified, but I convinced myself it's OK. That test is hardcoded in C to expect a Python int for some reason, so it's not a more general problem in numpy.

I'll merge in a few hours if there are no more comments.

@gfyoung
Copy link
Contributor Author

gfyoung commented Feb 17, 2016

@ahaldane : Thanks for taking the time to look at several of my PR's!

ahaldane added a commit that referenced this pull request Feb 17, 2016
BUG: Enforce dtype for randint singletons
@ahaldane ahaldane merged commit a2f5392 into numpy:master Feb 17, 2016
@ahaldane
Copy link
Member

Thanks @gfyoung

@gfyoung gfyoung deleted the randint_dtype_enforce branch February 17, 2016 23:44
charris added a commit that referenced this pull request Feb 19, 2016
@charris charris removed this from the 1.11.0 release milestone Feb 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants