Skip to content

Commit

Permalink
apacheGH-34031: [Python][DRAFT] Experiment with PyCapsule for communi…
Browse files Browse the repository at this point in the history
…cating C Data Interface pointers
  • Loading branch information
jorisvandenbossche authored and wjones127 committed Oct 1, 2023
1 parent 00efb06 commit c8704b2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion python/pyarrow/ipc.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from collections import namedtuple
import warnings

cimport cpython

cpdef enum MetadataVersion:
V1 = <char> CMetadataVersion_V1
Expand Down Expand Up @@ -815,6 +815,29 @@ cdef class RecordBatchReader(_Weakrefable):
self.reader = c_reader
return self

@staticmethod
def _import_from_c_capsule(stream):
cdef:
ArrowArrayStream* c_stream
shared_ptr[CRecordBatchReader] c_reader
RecordBatchReader self

# sanity checks
if not cpython.PyCapsule_IsValid(stream, 'arrowarraystream'):
raise ValueError(
"Not an ArrayArrayStream object"
)
c_stream = <ArrowArrayStream*>cpython.PyCapsule_GetPointer(
stream, 'arrowarraystream'
)

with nogil:
c_reader = GetResultValue(ImportRecordBatchReader(c_stream))

self = RecordBatchReader.__new__(RecordBatchReader)
self.reader = c_reader
return self

@staticmethod
def from_batches(Schema schema not None, batches):
"""
Expand Down

0 comments on commit c8704b2

Please sign in to comment.