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

Joris Van den Bossche commented on ARROW-13784:
-----------------------------------------------

Actually, we already check that the list of arrays and list of names should 
have the same length. But, in the special case of a list of arrays of length 
zero, we return just before that: 
https://github.com/apache/arrow/blob/26a34c3a2300620787806c5a8cee08ff30610e3e/python/pyarrow/table.pxi#L557-L569
 
So by moving the {{if len(names) != K:}} check before the {{if K == 0}} check, 
this should be fixed.

> [Python] Table.from_arrays should return a schema when array is empty but 
> names is not
> --------------------------------------------------------------------------------------
>
>                 Key: ARROW-13784
>                 URL: https://issues.apache.org/jira/browse/ARROW-13784
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>    Affects Versions: 4.0.1
>            Reporter: Abderrahmane Jaidi
>            Priority: Major
>              Labels: good-first-issue
>
> The `Table.from_arrays` method returns an empty schema when supplying an 
> empty arrays list but providing column names. As a result, the subsequent 
> `to_pandas` method returns an empty data frame with no column names.
> ```
> {{import pyarrow as pa}}
> {{arrays = []}}
> {{cols_names = ["col1", "col2"]}}
> {{table = pa.Table.from_arrays(arrays=arrays, names=cols_names)}}
> {{table.schema  # returns nothing}}
> {{df = table.to_pandas()}}
> {{df.head()}}
> {{Empty DataFrame
> Columns: []
> Index: [] # Expected column names to be visible here}}
> ```
> I assume that this is because a schema cannot be built without data types?



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

Reply via email to