Skip to content

Commit 95cebc4

Browse files
committed
feat: add test for arrow C stream schema selection in DataFrame
1 parent 3cab1db commit 95cebc4

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

python/tests/test_dataframe.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,33 @@ def test_arrow_c_stream_reader(df):
16371637
assert table.equals(expected)
16381638

16391639

1640+
def test_arrow_c_stream_schema_selection(fail_collect):
1641+
ctx = SessionContext()
1642+
1643+
batch = pa.RecordBatch.from_arrays(
1644+
[
1645+
pa.array([1, 2]),
1646+
pa.array([3, 4]),
1647+
pa.array([5, 6]),
1648+
],
1649+
names=["a", "b", "c"],
1650+
)
1651+
df = ctx.create_dataframe([[batch]])
1652+
1653+
requested_schema = pa.schema([("c", pa.int64()), ("a", pa.int64())])
1654+
reader = pa.RecordBatchReader._import_from_c_capsule(
1655+
df.__arrow_c_stream__(requested_schema)
1656+
)
1657+
batches = list(reader)
1658+
1659+
assert len(batches) == 1
1660+
assert batches[0].schema == requested_schema
1661+
expected_batch = pa.record_batch(
1662+
[pa.array([5, 6]), pa.array([1, 2])], names=["c", "a"]
1663+
)
1664+
assert batches[0].equals(expected_batch)
1665+
1666+
16401667
def test_to_pylist(df):
16411668
# Convert datafusion dataframe to Python list
16421669
pylist = df.to_pylist()

0 commit comments

Comments
 (0)