MCPcopy Create free account
hub / github.com/apache/arrow / test_random

Function test_random

python/pyarrow/tests/test_compute.py:3777–3801  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3775
3776
3777def test_random():
3778 # (note negative integer initializers are accepted)
3779 for initializer in ['system', 42, -42, b"abcdef"]:
3780 assert pc.random(0, initializer=initializer) == \
3781 pa.array([], type=pa.float64())
3782
3783 # System random initialization => outputs all distinct
3784 arrays = [tuple(pc.random(100).to_pylist()) for i in range(10)]
3785 assert len(set(arrays)) == len(arrays)
3786
3787 arrays = [tuple(pc.random(100, initializer=i % 7).to_pylist())
3788 for i in range(0, 100)]
3789 assert len(set(arrays)) == 7
3790
3791 # Arbitrary hashable objects can be given as initializer
3792 initializers = [object(), (4, 5, 6), "foo"]
3793 initializers.extend(os.urandom(10) for i in range(10))
3794 arrays = [tuple(pc.random(100, initializer=i).to_pylist())
3795 for i in initializers]
3796 assert len(set(arrays)) == len(arrays)
3797
3798 with pytest.raises(TypeError,
3799 match=r"initializer should be 'system', an integer, "
3800 r"or a hashable object; got \[\]"):
3801 pc.random(100, initializer=[])
3802
3803
3804@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
extendMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected