diff options
author | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2019-05-29 18:14:43 +0100 |
---|---|---|
committer | Kevin Sheppard <kevin.k.sheppard@gmail.com> | 2019-05-29 23:39:29 +0100 |
commit | 5a105dc6133000bcb4de6b30081605718522b0bf (patch) | |
tree | fa37c99f2851db4fdee9d1772571008a0c88ddf4 /numpy | |
parent | 48547423ce61c82b13dc0c400b2a57bad219cab1 (diff) | |
download | numpy-5a105dc6133000bcb4de6b30081605718522b0bf.tar.gz |
BUG: Fix RandomState argument name
RandomState's argument must be named seed for backward compat
closes #13669
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/random/mtrand.pyx | 16 | ||||
-rw-r--r-- | numpy/random/tests/test_randomstate_regression.py | 6 |
2 files changed, 15 insertions, 7 deletions
diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index a1364ac18..50c8a0b2f 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -36,7 +36,7 @@ cdef object int64_to_long(object x): cdef class RandomState: """ - RandomState(bit_generator=None) + RandomState(seed=None) Container for the slow Mersenne Twister pseudo-random number generator. Consider using a different BitGenerator with the Generator container @@ -55,14 +55,14 @@ cdef class RandomState: A fixed bit generator using a fixed seed and a fixed series of calls to 'RandomState' methods using the same parameters will always produce the same results up to roundoff error except when the values were incorrect. - `RandomState` is effectively frozen and will only recieve updates that + `RandomState` is effectively frozen and will only receive updates that are required by changes in the the internals of Numpy. More substantial changes, including algorithmic improvements, are reserved for `Generator`. Parameters ---------- - bit_generator : {None, int, array_like, BitGenerator}, optional + 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 @@ -94,11 +94,13 @@ cdef class RandomState: cdef object lock _poisson_lam_max = POISSON_LAM_MAX - def __init__(self, bit_generator=None): - if bit_generator is None: + def __init__(self, seed=None): + if seed is None: bit_generator = _MT19937() - elif not hasattr(bit_generator, 'capsule'): - bit_generator = _MT19937(bit_generator) + elif not hasattr(seed, 'capsule'): + bit_generator = _MT19937(seed) + else: + bit_generator = seed self._bit_generator = bit_generator capsule = bit_generator.capsule diff --git a/numpy/random/tests/test_randomstate_regression.py b/numpy/random/tests/test_randomstate_regression.py index 5bb1ddde5..cdd905929 100644 --- a/numpy/random/tests/test_randomstate_regression.py +++ b/numpy/random/tests/test_randomstate_regression.py @@ -164,3 +164,9 @@ class TestRegression(object): other_byteord_dt = '<i4' if sys.byteorder == 'big' else '>i4' with pytest.deprecated_call(match='non-native byteorder is not'): random.randint(0, 200, size=10, dtype=other_byteord_dt) + + def test_named_argument_initialization(self): + # GH 13669 + rs1 = np.random.RandomState(123456789) + rs2 = np.random.RandomState(seed=123456789) + assert rs1.randint(0, 100) == rs2.randint(0, 100) |