Skip to content

core.common.random_state is too strict for state input #32503

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

Closed
TomAugspurger opened this issue Mar 6, 2020 · 1 comment · Fixed by #32510
Closed

core.common.random_state is too strict for state input #32503

TomAugspurger opened this issue Mar 6, 2020 · 1 comment · Fixed by #32510
Assignees
Milestone

Comments

@TomAugspurger
Copy link
Contributor

The numpy RandomState seed can be an int, array-like, or BitGenerator

seed : {None, int, array_like, BitGenerator}, optional
    Random seed used to initialize the pseudo-random number generator or
    an instantized BitGenerator.  If an integer or array, used as a seed for
    the MT19937 BitGenerator. Values can be any integer between 0 and
    2**32 - 1 inclusive, an array (or other sequence) of such integers,
    or ``None`` (the default).  If `seed` is ``None``, then the `MT19937`
    BitGenerator is initialized by reading data from ``/dev/urandom``
    (or the Windows analogue) if available or seed from the clock
    otherwise.

Right now, we only pass through integers. Arrays (and BitGenerators if possible) should be passed through to RandomState at

if is_integer(state):
return np.random.RandomState(state)
.

Current Behavior

In [1]: import pandas as pd

In [2]: import numpy as np

In [3]: state_data = np.random.randint(0, 2**31, size=624, dtype='uint32')

In [4]: pd.core.common.random_state(state_data)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-4f97e41a5899> in <module>
----> 1 pd.core.common.random_state(state_data)

~/sandbox/pandas/pandas/core/common.py in random_state(state)
    415     else:
    416         raise ValueError(
--> 417             "random_state must be an integer, a numpy RandomState, or None"
    418         )
    419

ValueError: random_state must be an integer, a numpy RandomState, or None

Expected Output

Out[4]: RandomState(MT19937) at 0x115B16050
@xcz011
Copy link
Contributor

xcz011 commented Mar 7, 2020

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants