-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Updated Random Number Generation in Numpy #19706
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
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.
This looks great overall. Could you change the variable name of the generator from r
to rng
, or something else a bit more descriptive?
Surely |
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.
While it is generally good to use state-of-the art patterns, IMHO we we should push the change out further, likely to 3.6 or so.
This code doesn't work for numpy < 1.17. Since Matplotlib 3.5 will require numpy >= 1.17, we're technically ok with using it in the docs. However, I project that we will have lot's of users who are still on older numpy versions and will copy examples from the stable docs, only to find that np.random.default_rng()
doesn't exist and the example does not run. IMHO the downside of likely confusing users with non-running examples weighs heavier than not using the latest recommended API. This balance will tip eventually when more and more users have migrated to numpy 1.17+.
I therefore block until we have decided if we really want this already in Matplotlib 3.5.
Side-note: There are many many more uses of np.random
in the examples, all of which should be switched if we want to switch.
@timhoffm how about we mention it specifically as in hist.py file for developers running on numpy>=1.17 they should adopt this practice while the developers running on numpy<1.17 should adopt with the previous and since we will eventually have to switch to numpy >= 1.17. I propose lets keep both the changes till we start using numpy >=1.17 then we can remove the previous verison. |
I don't even under stand why numpy has done this. Like sure make other generators available, but why a whole new API? |
@jklymak Same here. |
There are fundamental changes https://numpy.org/doc/stable/reference/random/new-or-different.html#new-or-different. |
@timhoffm what are your views on my proposed solution ? |
I don't think we should clutter our examples with notes on different API versions of other libraries. Note that while the new random generator is recommended for new code, I've put the topic on the agenda for the developer call tomorrow. We'll discuss it there among the core devs. You are welcome to join the call if you want to take part in the discussion. |
There are still likely many users who are not on the latest numpy, the old way is not being deprecated, the change is to enable things that we do not need (and will never need) in our context, and if we change it in one place we should change it everywhere (which will be a lot of thrashing). In another few years we could re-consider, but for now we are going to respectfully decline this change. Thank you for your effort on this @rajpratyush! |
PR Summary
closes #19670
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).