You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Antoine Pitrou (Jira)" <ji...@apache.org> on 2022/04/20 12:10:00 UTC
[jira] [Commented] (ARROW-16254) [Python] Scalar constructors should be callable
[ https://issues.apache.org/jira/browse/ARROW-16254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17524932#comment-17524932 ]
Antoine Pitrou commented on ARROW-16254:
----------------------------------------
cc [~alenkaf] [~raulcd]
> [Python] Scalar constructors should be callable
> -----------------------------------------------
>
> Key: ARROW-16254
> URL: https://issues.apache.org/jira/browse/ARROW-16254
> Project: Apache Arrow
> Issue Type: Improvement
> Components: Python
> Reporter: Antoine Pitrou
> Priority: Major
> Fix For: 9.0.0
>
>
> Currently, to create a Scalar instance you must call the {{pa.scalar}} factory function. This works fine for the simplest types, but not for more elaborate ones.
> For example, in C++ it is trivial to create a {{ListScalar}} from the embedded {{std::shared_ptr<Array>}}. But not in Python:
> {code:python}
> >>> arr = pa.array(["abc", "def", "ghi"])
> >>> pa.ListScalar(arr)
> Traceback (most recent call last):
> Input In [7] in <cell line: 1>
> pa.ListScalar(arr)
> TypeError: __init__() takes exactly 0 positional arguments (1 given)
> {code}
> There is a clumsy workaround that creates an intermediate {{ListArray}} with trivial offsets:
> {code:python}
> >>> list_arr = pa.ListArray.from_arrays([0, len(arr)], arr)
> >>> list_arr[0]
> <pyarrow.ListScalar: ['abc', 'def', 'ghi']>
> {code}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)