Skip to content

Commit dcffc3a

Browse files
committed
fix: update test for arrow_c_stream_capsule_released to accept both destructor behaviors during decoupling from PyArrow
1 parent 9cae1d8 commit dcffc3a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

python/tests/test_dataframe.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,10 +1738,14 @@ def test_arrow_c_stream_capsule_released(ctx):
17381738

17391739
reader = pa.RecordBatchReader._import_from_c_capsule(capsule)
17401740
reader.read_all()
1741-
# PyArrow may or may not clear the capsule's destructor; both behaviours are
1742-
# accepted temporarily while decoupling from PyArrow
1741+
# PyArrow may or may not clear the capsule's destructor; accept both
1742+
# behaviours temporarily while decoupling from PyArrow. Record the
1743+
# destructor value but don't assert a specific value here so the test
1744+
# works against pyarrow builds that clear the destructor and those that
1745+
# don't. The key checks are that import succeeds and cleanup does not
1746+
# lead to a double free (ensured by deleting the reader and forcing
1747+
# garbage collection below).
17431748
_ = get_destructor(capsule)
1744-
# Pointer remains retrievable
17451749
assert get_ptr(capsule, b"arrow_array_stream")
17461750
pyerr_clear()
17471751

src/dataframe.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ impl PyDataFrame {
988988
let reader: Box<dyn RecordBatchReader + Send> = Box::new(reader);
989989

990990
let stream = FFI_ArrowArrayStream::new(reader);
991+
// This custom destructor is defensive to avoid a double free. It is
992+
// a temporary workaround until DataFusion's Python bindings decouple
993+
// from PyArrow.
991994
// The returned capsule allows zero-copy hand-off to PyArrow. When
992995
// PyArrow imports the capsule it assumes ownership of the stream and
993996
// nulls out the capsule's internal pointer so the destructor does not

0 commit comments

Comments
 (0)