File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1929,6 +1929,28 @@ def test_iter_then_arrow_c_stream_gc():
19291929 gc .collect ()
19301930
19311931
1932+ def test_iter_arrow_stream_reader_gc ():
1933+ """Iterate over DataFrame, consume __arrow_c_stream__ reader, then gc."""
1934+
1935+ ctx = SessionContext ()
1936+ df = ctx .from_pydict ({"a" : [1 , 2 ]})
1937+
1938+ batches = list (df )
1939+ assert len (batches ) == 1
1940+ assert batches [0 ].column (0 ).to_pylist () == [1 , 2 ]
1941+
1942+ reader = pa .RecordBatchReader ._import_from_c_capsule (df .__arrow_c_stream__ ())
1943+ table = reader .read_all ()
1944+ assert table .column (0 ).to_pylist () == [1 , 2 ]
1945+
1946+ del table
1947+ del reader
1948+ del batches
1949+ del df
1950+ del ctx
1951+ gc .collect ()
1952+
1953+
19321954def test_to_pylist (df ):
19331955 # Convert datafusion dataframe to Python list
19341956 pylist = df .to_pylist ()
You can’t perform that action at this time.
0 commit comments