forked from lance-format/lance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_datagen.py
More file actions
35 lines (26 loc) · 980 Bytes
/
test_datagen.py
File metadata and controls
35 lines (26 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright The Lance Authors
import math
import lance._datagen as datagen
import pyarrow as pa
import pytest
@pytest.mark.skipif(datagen.is_datagen_supported(), reason="datagen is supported")
def test_import_error():
with pytest.raises(
NotImplementedError, match="was not built with the datagen feature"
):
datagen.rand_batches(None)
@pytest.mark.skipif(not datagen.is_datagen_supported(), reason="datagen not supported")
def test_rand_batches():
import lance._datagen as datagen
schema = pa.schema(
[
pa.field("int", pa.int64()),
pa.field("vector", pa.list_(pa.float32(), 128)),
]
)
batches = datagen.rand_batches(schema, batch_size_bytes=16 * 1024, num_batches=10)
assert len(batches) == 10
for batch in batches:
assert batch.num_rows == math.ceil(16 * 1024 / (129 * 4))
assert batch.schema == schema