File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
18691890def test_to_pylist (df ):
18701891 # Convert datafusion dataframe to Python list
18711892 pylist = df .to_pylist ()
You can’t perform that action at this time.
0 commit comments