You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "Wes McKinney (Jira)" <ji...@apache.org> on 2019/09/25 03:06:00 UTC

[jira] [Resolved] (ARROW-6158) [Python] possible to create StructArray with type that conflicts with child array's types

     [ https://issues.apache.org/jira/browse/ARROW-6158?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wes McKinney resolved ARROW-6158.
---------------------------------
    Fix Version/s:     (was: 1.0.0)
                   0.15.0
       Resolution: Fixed

Issue resolved by pull request 5488
[https://github.com/apache/arrow/pull/5488]

> [Python] possible to create StructArray with type that conflicts with child array's types
> -----------------------------------------------------------------------------------------
>
>                 Key: ARROW-6158
>                 URL: https://issues.apache.org/jira/browse/ARROW-6158
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>            Reporter: Joris Van den Bossche
>            Assignee: Joris Van den Bossche
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.15.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> Using the Python interface as example. This creates a {{StructArray}} where the field types don't match the child array types:
> {code}
> a = pa.array([1, 2, 3], type=pa.int64())
> b = pa.array(['a', 'b', 'c'], type=pa.string())
> inconsistent_fields = [pa.field('a', pa.int32()), pa.field('b', pa.float64())]
> a = pa.StructArray.from_arrays([a, b], fields=inconsistent_fields) 
> {code}
> The above works fine. I didn't find anything that errors (eg conversion to pandas, slicing), also validation passes, but the type actually has the inconsistent child types:
> {code}
> In [2]: a
> Out[2]: 
> <pyarrow.lib.StructArray object at 0x7f450af52eb8>
> -- is_valid: all not null
> -- child 0 type: int64
>   [
>     1,
>     2,
>     3
>   ]
> -- child 1 type: string
>   [
>     "a",
>     "b",
>     "c"
>   ]
> In [3]: a.type
> Out[3]: StructType(struct<a: int32, b: double>)
> In [4]: a.to_pandas()
> Out[4]: 
> array([{'a': 1, 'b': 'a'}, {'a': 2, 'b': 'b'}, {'a': 3, 'b': 'c'}],
>       dtype=object)
> In [5]: a.validate() 
> {code}
> Shouldn't this be disallowed somehow? (it could be checked in the Python {{from_arrays}} method, but maybe also in {{StructArray::Make}} which already checks for the number of fields vs arrays and a consistent array length). 
> Similarly to discussion in ARROW-6132, I would also expect that this the {{ValidateArray}} catches this.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)