[ 
https://issues.apache.org/jira/browse/ARROW-8640?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17096145#comment-17096145
 ] 

Micah Kornfield commented on ARROW-8640:
----------------------------------------

It looks like from_buffers is a method declared on the parent class Array.  And 
 the type that the sample code is passing in is a struct (which should only 
have the nullability buffer).  To construct a dense union you need to 
instantiate a new UnionType.  I'm not seeing it the documentation for some 
reason but I think you can use the union method (definition pasted below).

 

 

{{def union(children_fields, mode, type_codes=None):}}
{{ """}}
{{ Create UnionType from children fields.}}
{{ A union is defined by an ordered sequence of types; each slot in the union}}
{{ can have a value chosen from these types.}}
{{ Parameters}}
{{ ----------}}
{{ fields : sequence of Field values}}
{{ Each field must have a UTF8-encoded name, and these field names are}}
{{ part of the type metadata.}}
{{ mode : str}}
{{ Either 'dense' or 'sparse'.}}
{{ type_codes : list of integers, default None}}
{{ Returns}}
{{ -------}}
{{ type : DataType}}

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

Reply via email to