File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434 WindowFrame ,
3535 column ,
3636 literal ,
37+ to_record_batch_stream ,
3738)
3839from 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+
18511877def test_arrow_stream_to_pylist (df ):
18521878 capsule = df .__arrow_c_stream__ ()
18531879 reader = pa .RecordBatchReader ._import_from_c_capsule (capsule )
You can’t perform that action at this time.
0 commit comments