Reputation: 109
I want a result such as below by using pyarrow:
[
{'value': 'bar', 'key': 'foo'},
{'value': 'bar', 'key': 'foo'},
{'value': 'bar', 'key': 'foo'}
]
Therefore I wrote the following code:
import pyarrow as pa
fields = [pa.array(['foo', 'foo', 'foo']), pa.array(['bar', 'bar', 'bar'])]
arr = pa.StructArray.from_arrays(['key', 'value'], fields)
print(arr)
But I get the following error that is related to "arr = pa.StructArray.from_arrays(['key', 'value'], fields)":
expected bytes, pyarrow.lib.StringArray found
why? How can I fix it?
Upvotes: 2
Views: 998
Reputation: 43877
You're close, I think you just swapped the arguments.
arr = pa.StructArray.from_arrays(fields, ['key', 'value'])
Also, what you call fields
are actually instances of pa.Array
. There is such a thing as pa.Field
so I found the name a little confusing.
As for that error, it is because it is looking at the second argument (which it expects to be a list of names (bytes
)) and finding instead a list of StringArray
.
Upvotes: 1