[python] Allow adding via iterators (#391)

Makes the following work so all the formats accepted by `create_table()`
are also accepted by `add()`
```
import lancedb
import pyarrow as pa

db = lancedb.connect("/tmp")

def make_batches():
    for i in range(5):
        yield pa.RecordBatch.from_arrays(
            [
                pa.array([[3.1, 4.1], [5.9, 26.5]]),
                pa.array(["foo", "bar"]),
                pa.array([10.0, 20.0]),
            ],
            ["vector", "item", "price"],
        )

schema = pa.schema([
    pa.field("vector", pa.list_(pa.float32())),
    pa.field("item", pa.utf8()),
    pa.field("price", pa.float32()),
])

tbl = db.create_table("table4", make_batches(), schema=schema)
tbl.add(make_batches())
```
This commit is contained in:
Ayush Chaurasia
2023-08-05 01:19:44 +05:30
committed by GitHub
parent cf977866d8
commit bbfadfe58d
2 changed files with 6 additions and 1 deletions

View File

@@ -101,6 +101,11 @@ def test_ingest_record_batch_iterator(tmp_path):
),
)
tbl_len = len(tbl)
tbl.add(batch_reader())
assert len(tbl) == tbl_len * 2
assert len(tbl.list_versions()) == 2
def test_create_mode(tmp_path):
db = lancedb.connect(tmp_path)