wjones127 commented on code in PR #37797:
URL: https://github.com/apache/arrow/pull/37797#discussion_r1338852560
##########
python/pyarrow/types.pxi:
##########
@@ -357,6 +357,57 @@ cdef class DataType(_Weakrefable):
_as_c_pointer(in_ptr)))
return pyarrow_wrap_data_type(result)
+ def __arrow_c_schema__(self):
+ """
+ Export to a ArrowSchema PyCapsule
+
+ Unlike _export_to_c, this will not leak memory if the capsule is not
used.
+ """
+ cdef:
+ ArrowSchema* c_schema = <ArrowSchema*>malloc(sizeof(ArrowSchema))
+ with nogil:
+ check_status(ExportType(deref(self.type), c_schema))
+ return cpython.PyCapsule_New(c_schema, 'arrowschema',
&pycapsule_schema_deleter)
+
+ @staticmethod
+ def _import_from_c_capsule(schema):
Review Comment:
I agree. In a future PR, I'd like to add support for importing implementors
of this protocol in `pa.schema`, `pa.table`, and so on. Just didn't want to
clutter this PR with that.
--
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]