feat(python): expose AsyncTable.to_lance (#3730)

## Summary

- expose the existing async Lance dataset conversion as
`AsyncTable.to_lance`
- preserve table version, branch, and refreshed storage options when
opening the dataset
- route internal async pandas/query paths through the public API
- cover normal tables, checked-out versions, branches, and forwarded
dataset options

## Testing

- `cd python && uv run --no-sync pytest python/tests/test_table.py -q`
- `cd python && uv run --no-sync pytest python/tests/test_query.py -q`
- `cd python && uv run --no-sync pytest --doctest-modules
python/lancedb/table.py -q`
- `uv run --project python --no-sync ruff format --check
python/python/lancedb/table.py python/python/lancedb/query.py
python/python/tests/test_table.py`
- `uv run --project python --no-sync ruff check .`

Fixes #1387
This commit is contained in:
kid
2026-07-29 04:31:06 +08:00
committed by GitHub
parent 1ebde1f06c
commit 72fc660f9e
3 changed files with 67 additions and 3 deletions
+47
View File
@@ -1257,6 +1257,53 @@ def test_branch_to_lance_targets_branch(tmp_path):
assert table.to_lance().count_rows() == 1
@pytest.mark.asyncio
async def test_async_to_lance(tmp_path):
pytest.importorskip("lance")
db = await lancedb.connect_async(tmp_path)
table = await db.create_table("t", [{"i": 1}])
dataset = await table.to_lance()
assert dataset.count_rows() == 1
@pytest.mark.asyncio
async def test_async_branch_to_lance_targets_branch(tmp_path):
pytest.importorskip("lance")
db = await lancedb.connect_async(tmp_path)
table = await db.create_table("t", [{"i": 1}])
branch = await table.branches.create("exp")
await branch.add([{"i": 2}])
assert (await branch.to_lance()).count_rows() == 2
assert (await table.to_lance()).count_rows() == 1
@pytest.mark.asyncio
async def test_async_to_lance_targets_checked_out_version(tmp_path):
pytest.importorskip("lance")
db = await lancedb.connect_async(tmp_path)
table = await db.create_table("t", [{"i": 1}])
version = await table.version()
await table.add([{"i": 2}])
checked_out = await db.open_table("t", version=version)
assert (await checked_out.to_lance()).count_rows() == 1
assert (await table.to_lance()).count_rows() == 2
@pytest.mark.asyncio
async def test_async_to_lance_forwards_dataset_options(tmp_path):
pytest.importorskip("lance")
db = await lancedb.connect_async(tmp_path)
table = await db.create_table("t", [{"i": 1}])
dataset = await table.to_lance(default_scan_options={"with_row_id": True})
assert "_rowid" in dataset.schema.names
@pytest.mark.asyncio
async def test_async_branches(tmp_path):
db = await lancedb.connect_async(tmp_path)