You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/04/28 12:08:03 UTC

[GitHub] [arrow] lidavidm commented on a change in pull request #7027: ARROW-8572: [Python] expose UnionArray fields to Python

lidavidm commented on a change in pull request #7027:
URL: https://github.com/apache/arrow/pull/7027#discussion_r416559505



##########
File path: python/pyarrow/array.pxi
##########
@@ -1720,6 +1720,39 @@ cdef class UnionArray(Array):
     Concrete class for Arrow arrays of a Union data type.
     """
 
+    def child(self, int pos):
+        """
+        Return the given child array as an individual array.
+
+        For sparse unions, the returned array has its offset, length,
+        and null count adjusted.
+
+        For dense unions, the returned array is unchanged.
+        """
+        cdef shared_ptr[CArray] result
+        result = (<CUnionArray*> self.ap).child(pos)
+        if result != NULL:
+            return pyarrow_wrap_array(result)
+        raise KeyError("UnionArray does not have child {}".format(pos))
+
+    @property
+    def type_codes(self):
+        """Get the type codes array."""
+        buf = pyarrow_wrap_buffer((<CUnionArray*> self.ap).type_codes())
+        return Array.from_buffers(int8(), len(self), [None, buf])
+
+    @property
+    def value_offsets(self):

Review comment:
       Thanks for the review! I renamed this to 'offsets' to be consistent with Python.




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

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