dangotbanned commented on issue #48349:
URL: https://github.com/apache/arrow/issues/48349#issuecomment-3617144584

   > pandas needs this for efficient .list[-1] operations with pyarrow-backed 
arrays. Currently, pandas must use slow Python loops as a workaround.
   
   For this specific case, you can do:
   
   ```py
   import pyarrow as pa
   import pyarrow.compute as pc
   
   arr = pa.array([[1, 2, 3], [4, 5], [6, 7, 8, 9]])
   
   parent_indices = arr.value_parent_indices()
   
   # NOTE: or `np.arange` if `pyarrow<21`
   value_indices = pa.arange(0, len(parent_indices), 1)
   
   # NOTE: These are the defaults, but you can preserve nulls by changing this
   options = pc.ScalarAggregateOptions(skip_nulls=True, min_count=1)
   
   grouped_last = (
       pa.Table.from_arrays([parent_indices, value_indices], ["parent", 
"value"])
       .group_by("parent", use_threads=False)
       .aggregate([("value", "hash_last", options)])
   )
   arr.values.take(grouped_last.column(1)).to_pylist()
   ```
   
   ```py
   [3, 5, 9]
   ```
   
   


-- 
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]

Reply via email to