jorisvandenbossche commented on code in PR #1346:
URL: https://github.com/apache/arrow-adbc/pull/1346#discussion_r1425348258
##########
python/adbc_driver_manager/adbc_driver_manager/_lib.pyx:
##########
@@ -316,23 +348,56 @@ cdef class ArrowSchemaHandle:
"""The address of the ArrowSchema."""
return <uintptr_t> &self.schema
+ def __arrow_c_schema__(self) -> object:
+ """Consume this object to get a PyCapsule."""
+ # Reference:
+ #
https://arrow.apache.org/docs/dev/format/CDataInterface/PyCapsuleInterface.html#create-a-pycapsule
+ cdef CArrowSchema* allocated = <CArrowSchema*>
malloc(sizeof(CArrowSchema))
+ allocated.release = NULL
+ capsule = PyCapsule_New(
+ <void*>allocated, "arrow_schema", &pycapsule_schema_deleter,
+ )
+ memcpy(allocated, &self.schema, sizeof(CArrowSchema))
+ self.schema.release = NULL
+ return capsule
+
cdef class ArrowArrayHandle:
"""
A wrapper for an allocated ArrowArray.
+
+ This object implements the Arrow PyCapsule interface.
"""
cdef:
CArrowArray array
@property
def address(self) -> int:
- """The address of the ArrowArray."""
+ """
+ The address of the ArrowArray.
+ """
return <uintptr_t> &self.array
+ def __arrow_c_array__(self, requested_schema=None) -> object:
+ """Consume this object to get a PyCapsule."""
+ if requested_schema is not None:
+ raise NotImplementedError("requested_schema")
+
+ cdef CArrowArray* allocated = <CArrowArray*>
malloc(sizeof(CArrowArray))
+ allocated.release = NULL
+ capsule = PyCapsule_New(
+ <void*>allocated, "arrow_array", pycapsule_array_deleter,
+ )
+ memcpy(allocated, &self.array, sizeof(CArrowArray))
+ self.array.release = NULL
+ return capsule
Review Comment:
And realizing now, this implementation is actually also wrong -> it needs to
return two capsules, one for the ArrowArray but also one for the ArrowSchema.
And this handle only has the array. So I don't think we can add this dunder
here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]