[
https://issues.apache.org/jira/browse/ARROW-16254?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17525580#comment-17525580
]
Antoine Pitrou commented on ARROW-16254:
----------------------------------------
It does not if you pass an existing PyArrow array:
{code}
>>> arr = pa.array(["abc", "def", "ghi"])
>>> pa.scalar(arr)
Traceback (most recent call last):
...
ArrowInvalid: Could not convert <pyarrow.lib.StringArray object at
0x7f79ab490880>
[
"abc",
"def",
"ghi"
] with type pyarrow.lib.StringArray: did not recognize Python value type when
inferring an Arrow data type
>>> pa.scalar(arr, type=pa.list_(arr.type))
Traceback (most recent call last):
Input In [4] in <cell line: 1>
pa.scalar(arr, type=pa.list_(arr.type))
File pyarrow/scalar.pxi:1049 in pyarrow.lib.scalar
chunked = GetResultValue(ConvertPySequence(value, None, options, pool))
File pyarrow/error.pxi:144 in pyarrow.lib.pyarrow_internal_check_status
return check_status(status)
File pyarrow/error.pxi:123 in pyarrow.lib.check_status
raise ArrowTypeError(message)
ArrowTypeError: Expected bytes, got a 'pyarrow.lib.StringScalar' object
{code}
> [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)