Skip to content

Commit a3194ba

Browse files
committed
test: add unit test for converting DataFrame to Arrow Table from record batches
1 parent ca13f48 commit a3194ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

python/tests/test_arrow_interop.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pyarrow as pa
2+
import pytest
3+
4+
5+
def test_table_from_batches_with_dataframe(ctx):
6+
batch1 = pa.record_batch({"a": pa.array([1, 2]), "b": pa.array(["x", "y"])})
7+
batch2 = pa.record_batch({"a": pa.array([3, 4]), "b": pa.array(["z", "w"])})
8+
df = ctx.create_dataframe([[batch1], [batch2]])
9+
10+
try:
11+
table = pa.Table.from_batches(df)
12+
except TypeError as err: # pragma: no cover - failure path
13+
pytest.fail(f"TypeError raised when converting DataFrame to Arrow Table: {err}")
14+
15+
expected = pa.Table.from_batches([batch1, batch2])
16+
assert table.equals(expected)

0 commit comments

Comments
 (0)