-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: random_state should permit numpy.random.Generator #38100
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
Comments
In the short-term, I think it's probably acceptable for pandas to take the BitGenerator used by the input Generator ( But long-term it's probably best to convert everything to use |
Since the minimum NumPy version should now be 1.17 (according to NEP29), which provides the new Generator objects, are these changes that can now be made? |
@jamesmyatt we are still supporting numpy 1.6 in upcoming release but not averse to actually bumping it (separate PR) |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Output:
Problem description
Best practice since Numpy 1.17 for creating random number generators is to use
numpy.random.default_rng
:https://numpy.org/doc/stable/reference/random/index.html?highlight=random#quick-start. This returns a
numpy.random.Generator
object. It should not be necessary to extract the underlyingBitGenerator
or convert it manually to a legacynumpy.random.RandomState
.Closest issues I can find are #28440 (mentions performance only) and #32503. Code is here:
pandas/pandas/core/common.py
Line 366 in 78d1498
Current simplest workaround is as follows. I've confirmed that it advances
rng
.Expected Output
Code above should not throw an error.
Output of
pd.show_versions()
pandas : 1.1.4
numpy : 1.19.4
pytz : 2020.4
dateutil : 2.8.1
pip : 20.2.4
setuptools : 49.6.0.post20201009
Cython : None
pytest : 6.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 2.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.51.2
The text was updated successfully, but these errors were encountered: