pyarrow get int from pyarrow int array based on index

Viewed 264

I am facing this really annoying issue of pyarrow not giving me the int from a list/array :((

So, I have:

x=pa.array([1,2,3])
x[0]
<pyarrow.Int64Scalar: 1>

I just want the 1 back! I tried:

>>> x[0].as_py
<built-in method as_py of pyarrow.lib.Int64Scalar object at 0x7f62a3abc0c0>

however, when I do this on strings, it works as I expect:

>>> y=pa.array(['1','2','3'])
>>> str(y[0])
1

why does this not work for int? :((

1 Answers

Because as_py is a method, so you need to have parenthesis to call the method:

>>> x[0].as_py()
1

And the reason str(y[0]) works is it's because of __str__ method which is used when an object is passed to str function.

Related