Skip to content

Commit e20046a

Browse files
committed
test: add cleanup test for iterating and streaming with arrow C
1 parent e70b16e commit e20046a

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

python/tests/test_dataframe.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,27 @@ def test_arrow_stream_to_pandas(df):
18661866
assert pdf.shape == (3, 3)
18671867

18681868

1869+
def test_iter_then_arrow_c_stream_gc():
1870+
"""Iterate via __iter__ and __arrow_c_stream__ repeatedly to ensure cleanup."""
1871+
1872+
for _ in range(3):
1873+
ctx = SessionContext()
1874+
df = ctx.from_pydict({"a": [1, 2]})
1875+
1876+
batches = list(df)
1877+
assert len(batches) == 1
1878+
assert batches[0].column(0).to_pylist() == [1, 2]
1879+
1880+
reader = pa.RecordBatchReader._import_from_c_capsule(df.__arrow_c_stream__())
1881+
table = pa.Table.from_batches(reader)
1882+
assert table.column("a").to_pylist() == [1, 2]
1883+
1884+
del reader
1885+
del df
1886+
del ctx
1887+
gc.collect()
1888+
1889+
18691890
def test_to_pylist(df):
18701891
# Convert datafusion dataframe to Python list
18711892
pylist = df.to_pylist()

0 commit comments

Comments
 (0)