You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "wjones127 (via GitHub)" <gi...@apache.org> on 2023/09/27 16:10:07 UTC

[GitHub] [arrow] wjones127 commented on a diff in pull request #37797: GH-35531: [Python] C Data Interface PyCapsule Protocol

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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org