core.common.random_state is too strict for state input · Issue #32503 · pandas-dev/pandas (original) (raw)
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) in ----> 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