[Python] Allow PyCapsule Interface in `pyarrow.scalar` constructor?
Describe the enhancement requested
Should the pyarrow.scalar constructor check for the PyCapsule Interface? It would allow any input with __arrow_c_array__, additionally validating that the input is a length-1 array.
In this case it's less important for the speed of sharing large data across multiple libraries than it is for the reliability of communicating Arrow data.
An existing workaround is to use pa.array(other_scalar).slice(0, 1), so it's not clear whether the pa.scalar constructor should or should not check for this.
cc @jorisvandenbossche
Component(s)
Python
take
Thank you for opening up the issue, @kylebarron!
I think allowing and checking for 1-length objects implementing __arrow_c_array__ in pyarrow.scalar is a good idea and should be fairly straightforward to implement. However, I'm a bit confused about the workaround you're referring to. Could you provide more context or a reproducible example of the workaround? This would help me better understand the use case.
However, I'm a bit confused about the workaround you're referring to.
Oh I had a typo in my original code. I meant pyarrow.array(external_scalar)[0].
So that uses the implementation of reading __arrow_c_array__ from the pyarrow.array constructor, and then selects the first scalar.