Skip to content

Commit 687c226

Browse files
committed
test: add test for arrow stream context drop to prevent segfaults
1 parent 903f63d commit 687c226

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

python/tests/test_dataframe.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
WindowFrame,
3535
column,
3636
literal,
37+
to_record_batch_stream,
3738
)
3839
from datafusion import (
3940
functions as f,
@@ -1848,6 +1849,31 @@ def test_arrow_c_stream_context_drop_no_segfault():
18481849
gc.collect()
18491850

18501851

1852+
def test_arrow_streams_context_drop_no_segfault():
1853+
"""__arrow_c_stream__ and to_record_batch_stream survive context drop."""
1854+
1855+
for _ in range(5):
1856+
ctx = SessionContext()
1857+
df = ctx.sql("SELECT 1 AS a")
1858+
capsule = df.__arrow_c_stream__()
1859+
stream = to_record_batch_stream(df)
1860+
del df
1861+
del ctx
1862+
1863+
reader = pa.RecordBatchReader._import_from_c_capsule(capsule)
1864+
del capsule
1865+
table = reader.read_all()
1866+
assert table.column("a").to_pylist() == [1]
1867+
del reader
1868+
1869+
batches = list(stream)
1870+
assert len(batches) == 1
1871+
assert batches[0].column("a").to_pylist() == [1]
1872+
del batches
1873+
del stream
1874+
gc.collect()
1875+
1876+
18511877
def test_arrow_stream_to_pylist(df):
18521878
capsule = df.__arrow_c_stream__()
18531879
reader = pa.RecordBatchReader._import_from_c_capsule(capsule)

0 commit comments

Comments
 (0)