Esempio n. 1
0
 def test_sample_random_state(self, func_str, arg):
     # GH32503
     df = pd.DataFrame({"col1": range(10, 20), "col2": range(20, 30)})
     result = df.sample(n=3, random_state=eval(func_str)(arg))
     expected = df.sample(n=3,
                          random_state=com.random_state(
                              eval(func_str)(arg)))
     tm.assert_frame_equal(result, expected)
Esempio n. 2
0
 def test_sample_random_state(self, func_str, arg, frame_or_series):
     # GH#32503
     obj = DataFrame({"col1": range(10, 20), "col2": range(20, 30)})
     if frame_or_series is Series:
         obj = obj["col1"]
     result = obj.sample(n=3, random_state=eval(func_str)(arg))
     expected = obj.sample(n=3, random_state=com.random_state(eval(func_str)(arg)))
     tm.assert_equal(result, expected)
Esempio n. 3
0
def test_random_state():
    import numpy.random as npr

    # Check with seed
    state = com.random_state(5)
    assert state.uniform() == npr.RandomState(5).uniform()

    # Check with random state object
    state2 = npr.RandomState(10)
    assert com.random_state(state2).uniform() == npr.RandomState(10).uniform()

    # check with no arg random state
    assert com.random_state() is np.random

    # check array-like
    # GH32503
    state_arr_like = npr.randint(0, 2 ** 31, size=624, dtype="uint32")
    assert (
        com.random_state(state_arr_like).uniform()
        == npr.RandomState(state_arr_like).uniform()
    )

    # Check BitGenerators
    # GH32503
    if not np_version_under1p17:
        assert (
            com.random_state(npr.MT19937(3)).uniform()
            == npr.RandomState(npr.MT19937(3)).uniform()
        )
        assert (
            com.random_state(npr.PCG64(11)).uniform()
            == npr.RandomState(npr.PCG64(11)).uniform()
        )

    # Error for floats or strings
    msg = (
        "random_state must be an integer, array-like, a BitGenerator, "
        "a numpy RandomState, or None"
    )
    with pytest.raises(ValueError, match=msg):
        com.random_state("test")

    with pytest.raises(ValueError, match=msg):
        com.random_state(5.5)
Esempio n. 4
0
def test_random_state():
    import numpy.random as npr
    # Check with seed
    state = com.random_state(5)
    assert state.uniform() == npr.RandomState(5).uniform()

    # Check with random state object
    state2 = npr.RandomState(10)
    assert com.random_state(state2).uniform() == npr.RandomState(10).uniform()

    # check with no arg random state
    assert com.random_state() is np.random

    # Error for floats or strings
    with pytest.raises(ValueError):
        com.random_state('test')

    with pytest.raises(ValueError):
        com.random_state(5.5)
Esempio n. 5
0
def test_random_state():
    import numpy.random as npr
    # Check with seed
    state = com.random_state(5)
    assert state.uniform() == npr.RandomState(5).uniform()

    # Check with random state object
    state2 = npr.RandomState(10)
    assert com.random_state(state2).uniform() == npr.RandomState(10).uniform()

    # check with no arg random state
    assert com.random_state() is np.random

    # Error for floats or strings
    with pytest.raises(ValueError):
        com.random_state('test')

    with pytest.raises(ValueError):
        com.random_state(5.5)
Esempio n. 6
0
def test_random_state():
    import numpy.random as npr

    # Check with seed
    state = com.random_state(5)
    assert state.uniform() == npr.RandomState(5).uniform()

    # Check with random state object
    state2 = npr.RandomState(10)
    assert com.random_state(state2).uniform() == npr.RandomState(10).uniform()

    # check with no arg random state
    assert com.random_state() is np.random

    # Error for floats or strings
    msg = "random_state must be an integer, a numpy RandomState, or None"
    with pytest.raises(ValueError, match=msg):
        com.random_state("test")

    with pytest.raises(ValueError, match=msg):
        com.random_state(5.5)
Esempio n. 7
0
 def random_color(column):
     """ Returns a random color represented as a list of length 3"""
     # GH17525 use common._random_state to avoid resetting the seed
     rs = com.random_state(column)
     return rs.rand(3).tolist()
Esempio n. 8
0
 def random_color(column):
     """ Returns a random color represented as a list of length 3"""
     # GH17525 use common._random_state to avoid resetting the seed
     rs = com.random_state(column)
     return rs.rand(3).tolist()
Esempio n. 9
0
def _random_color(column: int) -> List[float]:
    """Get a random color represented as a list of length 3"""
    # GH17525 use common._random_state to avoid resetting the seed
    rs = com.random_state(column)
    return rs.rand(3).tolist()