js8544 commented on issue #37625:
URL: https://github.com/apache/arrow/issues/37625#issuecomment-1711462121
> I have a 2D array with dictionaries in it and I want to flatten the values
of it using the first dictionary
I don't see any dictionary in your example though. Am I missing something?
The array you provided is of type `list<item: struct<key: int64>>`
```python
>>> print(pa.array([[{'key': 1}], None, [{'key': 2}]]).type)
list<item: struct<key: int64>>
```
If you want the flattened result to contain a `null` for null lists, you can
map the `null` list to a list containing a single `null`
```python
>>> arr = pa.array([[1], None, [2]])
>>> arr = pa.compute.coalesce(arr, pa.scalar([None],
type=pa.list_(pa.int64())))
>>> arr
list<item: struct<key: int64>>
[
[
1
],
[
null
],
[
2
]
]
>>> arr.flatten()
<pyarrow.lib.Int64Array object at 0xffff61b29300>
[
1,
null,
2
]
```
Does this work for you?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]