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

Function test_random

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

Source from the content-addressed store, hash-verified

3948
3949
3950def test_random():
3951 # (note negative integer initializers are accepted)
3952 for initializer in ['system', 42, -42, b"abcdef"]:
3953 assert pc.random(0, initializer=initializer) == \
3954 pa.array([], type=pa.float64())
3955
3956 # System random initialization => outputs all distinct
3957 arrays = [tuple(pc.random(100).to_pylist()) for i in range(10)]
3958 assert len(set(arrays)) == len(arrays)
3959
3960 arrays = [tuple(pc.random(100, initializer=i % 7).to_pylist())
3961 for i in range(0, 100)]
3962 assert len(set(arrays)) == 7
3963
3964 # Arbitrary hashable objects can be given as initializer
3965 initializers = [object(), (4, 5, 6), "foo"]
3966 initializers.extend(os.urandom(10) for i in range(10))
3967 arrays = [tuple(pc.random(100, initializer=i).to_pylist())
3968 for i in initializers]
3969 assert len(set(arrays)) == len(arrays)
3970
3971 with pytest.raises(TypeError,
3972 match=r"initializer should be 'system', an integer, "
3973 r"or a hashable object; got \[\]"):
3974 pc.random(100, initializer=[])
3975
3976
3977@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