AlenkaF commented on code in PR #38472:
URL: https://github.com/apache/arrow/pull/38472#discussion_r1423896057


##########
python/pyarrow/array.pxi:
##########
@@ -1778,6 +1778,49 @@ cdef class Array(_PandasConvertible):
 
         return pyarrow_wrap_array(array)
 
+    def __dlpack__(self, stream=None):
+        """Export a primitive array as a DLPack capsule.
+
+        Parameters
+        ----------
+        stream : int, optional
+            A Python integer representing a pointer to a stream. Currently not 
supported.
+            Stream is provided by the consumer to the producer to instruct the 
producer
+            to ensure that operations can safely be performed on the array.
+
+        Returns
+        -------
+        capsule : PyCapsule
+            A DLPack capsule for the array, pointing to a DLManagedTensor.
+        """
+        cdef CResult[DLManagedTensor*] c_dlm_tensor
+
+        if stream is None:
+            c_dlm_tensor = ExportToDLPack(pyarrow_unwrap_array(self))
+            dlm_tensor = GetResultValue(c_dlm_tensor)
+
+            return PyCapsule_New(dlm_tensor, 'dltensor', 
dlpack_pycapsule_deleter)
+        else:
+            raise NotImplementedError(
+                "Only stream=None is supported."
+            )
+
+    def __dlpack_device__(self):
+        """
+        Performs the operation __dlpack_device__.
+
+        Returns
+        -------
+        tuple : Tuple[DLDeviceType, int]

Review Comment:
   Decided to do the same as Numpy at the end - returning `tuple[int, int]` =)
   No need to complicate if it is not necessary.



-- 
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]

Reply via email to