-
-
Notifications
You must be signed in to change notification settings - Fork 11k
DOC: Clarify behavior in np.random.uniform #7026
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
Conversation
Note that this PR only checks for whether |
I think you should add the |
Could I put a warning perhaps for equality? I'm afraid to throw errors because seemingly innocuous inputs can cause errors like these inputs |
In closer look, the case for |
Hmmm...I suppose so. I guess you could expand the doc string to say that it returns |
If a user wants to generate random numbers between |
Yup, maybe all this needs is a docstring change and no error raising. The case where |
Hmmm...I guess it's a question of consistency in the codebase then. We check that |
Also, if we go with allowing such flexibility, I might also suggest changing the variable names since they would no longer be completely representative of what goes on behind the scenes. Though given that they are keyword args, that may not be plausible at the moment for backwards-compatibility reasons. |
I'd say the main reason |
@jaimefrio : Ah, that is true. I'm perfectly alright with keeping Those would be the two things I would propose. The first one looks quite straightforward, but the second one, not as much. I'd be curious to hear what others think as well about these proposals. |
@jaimefrio : I've decided to just update documentation to make sure that users are aware of this behavior, given that the C code is written to allow this flexibility. As this is just a change in documentation, this PR should be good to merge unless someone has differing opinions about how to handle this functionality for |
cases when ``low`` == ``high`` and ``low`` > ``high``. In | ||
the former case, an ndarray containing of ints all equal to | ||
``low`` will be returned. In the latter case, numbers will | ||
be drawn from the uniform distribution [``high``, ``low``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think high
is always the open side of the interval, and low
always the closed one, so if low > high
, then the interval is (high, low]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, that is right. I'll make the correction as soon as I can sit down in front of a proper computer screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaimefrio : Fixed the documentation.
I have sent a message to the mailing list. I would like to hear what people with more hands on experience using this function in the real world have to say. If there is no substantial discussion there, and I haven't merged this by the end of the week, please ping me and I will. |
👍 Sounds good. Thanks for sending the email out! |
@jaimefrio : In light of the discussion, what do you think is best at this point? |
I would simplify it down to something like the following:
|
@rkern : When you say "officially undefined," do you mean that when you call something like |
It just means that we don't guarantee what the results will be in the future or that it will continue to return a value without an |
Although the arguments are specified as 'high' and 'low', it is possible to pass in values for 'low' and 'high' where 'low' >= 'high' and still obtain well-defined behavior. The documentation has been expanded to reflect this fact, with a note to discourage passing in arguments satisfying 'low' > 'high'.
@jaimefrio , @rkern : Comment has been updated. Should be good to merge since this change has no effect on any code. |
LGTM. |
DOC: Clarify behavior in np.random.uniform
Fixes issue in
np.random.uniform
in which it was generating numbers for invalid bounds such aslow = 0 and high = -1. It now raises a
ValueError
instead likenp.random.randint
when such arguments are passed in.