arrow icon indicating copy to clipboard operation
arrow copied to clipboard

[Python] Allow PyCapsule Interface in `pyarrow.scalar` constructor?

Open kylebarron opened this issue 1 year ago • 1 comments

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

kylebarron avatar Sep 25 '24 21:09 kylebarron

take

Lukedowling444 avatar Oct 12 '24 11:10 Lukedowling444

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.

AlenkaF avatar Mar 04 '25 12:03 AlenkaF

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.

kylebarron avatar Mar 04 '25 14:03 kylebarron