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/23 20:35:35 UTC
[GitHub] [arrow] lidavidm opened a new pull request #7027: ARROW-8572: [Python] expose UnionArray fields to Python
lidavidm opened a new pull request #7027:
URL: https://github.com/apache/arrow/pull/7027
- Adds an explicit range check to `UnionArray.child`
- Exposes `child`, `value_offsets`, and `type_codes` to Python. (In Python, they're wrapped in arrays for you to save you the trouble.)
This lets you losslessly assemble and then disassemble a union array in 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
[GitHub] [arrow] jorisvandenbossche commented on a change in pull request #7027: ARROW-8572: [Python] expose UnionArray fields to Python
Posted by GitBox <gi...@apache.org>.
jorisvandenbossche commented on a change in pull request #7027:
URL: https://github.com/apache/arrow/pull/7027#discussion_r416374325
##########
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:
For ListArray, this is called "offsets" (not sure if we prefer consistency within the python api, or consistency with the c++ api)
----------------------------------------------------------------
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
[GitHub] [arrow] lidavidm commented on a change in pull request #7027: ARROW-8572: [Python] expose UnionArray fields to Python
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [arrow] github-actions[bot] commented on pull request #7027: ARROW-8572: [Python] expose UnionArray fields to Python
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #7027:
URL: https://github.com/apache/arrow/pull/7027#issuecomment-618659884
https://issues.apache.org/jira/browse/ARROW-8572
----------------------------------------------------------------
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