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
Confusing argument order for random.randint #9573
Comments
So using the pep457(?) convention, the function has the signature The bug and confusion here is the handling of keyword arguments, not the way in which positional parameters are interpreted (which matches |
This isn't fully BC since this currently raises an error, and so an error would change to a warning and a vector output. It might have been clearer if this function was called |
Fair points. Would getting rid of the keyword arguments altogether (like |
Definitions should perhaps be (like range)
which aren't quite perfect, but would explain the intent. |
Instead of re-ordering
in this way I can create a PR for the same if this makes sense. |
Hello, I just came across this issue exactly because I find very confusing the documentation about The current documentation shows I would propose to adopt the same notation used by the official python documentation for the
Do you think I can directly open a PR for that? |
@ffranchina I think that is a good idea. Open one and let's see how the docs render in the PR CI run. |
Still not resolved in version 1.26 docs, i.e. low is required, high is optional which is wrong. |
Not sure if this is covered anywhere already, feel free to close if this is the case.
Without having the numpy documentation open, and just looking at the argument names for
random.randint
, the results I got were.. confusing, to say the least.Without looking at the docs, what would the following code do:
random.randint(low=2, size=5)
?My guess would be that it would give back five integers larger than or equal to 2. However, the result was quite different:
array([1, 0, 0, 1, 1])
.Wait, so I specified
low=2
, but got back numbers which are all lower thanlow
? What the...The docs didn't help much at first, either: "unless high=None, in which case this parameter is one above the highest such integer" - what? Until I stumbled upon this: "If high is None (the default), then results are from [0, low)."
So
high
andlow
are switched based on the value of one of the parameters, which makes things very confusing. Much cleaner would be the following function definition:Of course, this would not permit something like
randint(1, 2)
, butrandint(low=1, high=2)
is arguably more readable anyway. For backwards compatibility, a check could be built in which checks iflow
is greater thanhigh
, in which case the order can be reversed (while raising a warning).The text was updated successfully, but these errors were encountered: