MCPcopy Index your code
hub / github.com/ray-project/ray / test_basic

Function test_basic

python/ray/data/tests/test_random_access.py:9–32  ·  view source on GitHub ↗
(ray_start_regular_shared, pandas)

Source from the content-addressed store, hash-verified

7
8@pytest.mark.parametrize("pandas", [False, True])
9def test_basic(ray_start_regular_shared, pandas):
10 ds = ray.data.range(100, override_num_blocks=10)
11 ds = ds.add_column("key", lambda b: b["id"] * 2)
12 ds = ds.add_column("embedding", lambda b: b["id"] ** 2)
13 if not pandas:
14 ds = ds.map_batches(
15 lambda df: pyarrow.Table.from_pandas(df), batch_format="pandas"
16 )
17
18 rad = ds.to_random_access_dataset("key", num_workers=1)
19
20 def expected(i):
21 return {"id": i, "key": i * 2, "embedding": i**2}
22
23 # Test get.
24 assert ray.get(rad.get_async(-1)) is None
25 assert ray.get(rad.get_async(200)) is None
26 for i in range(100):
27 assert ray.get(rad.get_async(i * 2 + 1)) is None
28 assert ray.get(rad.get_async(i * 2)) == expected(i)
29
30 # Test multiget.
31 results = rad.multiget([-1] + list(range(0, 20, 2)) + list(range(1, 21, 2)) + [200])
32 assert results == [None] + [expected(i) for i in range(10)] + [None] * 10 + [None]
33
34
35def test_empty_blocks(ray_start_regular_shared):

Callers

nothing calls this directly

Calls 9

expectedFunction · 0.85
listFunction · 0.85
add_columnMethod · 0.80
map_batchesMethod · 0.80
rangeFunction · 0.70
getMethod · 0.65
get_asyncMethod · 0.45
multigetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…