[
https://issues.apache.org/jira/browse/ARROW-8640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17096156#comment-17096156
]
Anish Biswas commented on ARROW-8640:
-------------------------------------
Yup, thanks that was the trick!
{code:java}
type_arr = pa.union(pa.struct([pa.field("0", arr1.type) , pa.field("1",
arr2.type)]), "dense", [0,1])
arr4 = pa.UnionArray.from_buffers(type_arr, 5, arr.buffers()[0:3],
children=[arr1, arr2])
{code}
Creating a type_arr and then passing it into the types field worked. Thanks!
Just a follow-up question. Why are we required to place the Datatype in fields,
finally accumulated by the struct instead of passing a list of Datatype in
which the position determines the type-codes?
> pyarrow.UnionArray.from_buffers() expected number of buffers (1) did not
> match the passed number (3)
> ----------------------------------------------------------------------------------------------------
>
> Key: ARROW-8640
> URL: https://issues.apache.org/jira/browse/ARROW-8640
> Project: Apache Arrow
> Issue Type: Bug
> Reporter: Anish Biswas
> Priority: Major
>
> {code:python}
> arr1 = pa.array([1,2,3,4,5])arr1.buffers()
> arr2 = pa.array([1.1,2.2,3.3,4.4,5.5])
> types = pa.array([0, 1, 0, 0, 1, 1, 0], type='int8')
> value_offsets = pa.array([1, 0, 0, 2, 1, 2, 3],
> type='int32')value_offsets.buffers()
> arr = pa.UnionArray.from_dense(types, value_offsets,
> [arr1, arr2])
> arr4 = pa.UnionArray.from_buffers(pa.struct([pa.field("0", arr1.type) ,
> pa.field("1", arr2.type)]), 5, arr.buffers()[0:3], children=[arr1, arr2])
> {code}
> The problem here arises when I try to produce the Union Array via buffers,
> according to the Columnar Documentation I need 3 buffers to produce a dense
> Union Array. But when I try this, there is the error `Type's expected number
> of buffers (1) did not match the passed number (3)`.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)