You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rows in a ListArray are ListScalar class which do not have an option to be sorted AFAIK.
But they can be constructed, zero-copy, as arrays which can be sorted. Maybe this kind of sort would only need some extra logic?
Hello, would you be also willing to consider adding aggregate functions to the list methods: list_min, list_max, list_mean, list_median, and list_sum? Thanks
does the whole thing in C++, rather than extracting each row as a scalar and sorting each one individually myself (especially from Python!)
Of course! This clarification was needed though, thanks =)
I was thinking we might not need a separate kernel in C++ but do it efficiently with existing ones. Not sure though!
would you be also willing to consider adding aggregate functions to the list methods: list_min, list_max, list_mean, list_median, and list_sum?
I would personally support additions of new kernels but I have to point out this is an effort that would need developer help from the community (meaning, contributions are most welcome! :) )
I was thinking we might not need a separate kernel in C++ but do it efficiently with existing ones. Not sure though!
After talking to Rok and looking at the docs I understand better that sorting values "per row" in a list array would need a new kernel due to having all values of the list stored in one buffer. The kernel would need to take offsets into account and sort values in separate intervals.
I'm slightly surprised we don't have this yet, not even as an aggregation. It would be nice to add it as a C++ kernel indeed.
@raisadz for the min/max/mean/median/sum, you could use aggregation kernels, though I'm sure this can be done more efficiently working directly on the ListArray:
I'm slightly surprised we don't have this yet, not even as an aggregation. It would be nice to add it as a C++ kernel indeed.
@raisadz for the min/max/mean/median/sum, you could use aggregation kernels, though I'm sure this can be done more efficiently working directly on the ListArray:
import pyarrow as pa
import pyarrow.compute as pc
arr = pa.array([[1, 2, None, 0], [7, 7, None, 0], [1, 2, 3]])
offsets = pc.list_parent_indices(arr)
table = pa.Table.from_arrays([arr.values, offsets], names=["values", "offsets"])
table.group_by(["offsets"]).aggregate([("values", "min")])
pyarrow.Table
offsets: int64
values_min: int64
offsets: [[0,1,2]]
values_min: [[0,0,1]]
Thanks a lot for pointing me to the aggregation kernels @rok, it seems to work well for my task!
Great to hear @raisadz ! Do keep in mind aggregate kernels here might be less optimal than what's possible to do operating directly on a ListArray and it's perhaps still worth investigating c++ kernels for your usecase.
This issue has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this issue will be closed in 14 days. If this improvement is still desired but has no current owner, please add the 'Status: needs champion' label.
Activity
AlenkaF commentedon Nov 5, 2025
Rows in a
ListArrayareListScalarclass which do not have an option to be sorted AFAIK.But they can be constructed, zero-copy, as arrays which can be sorted. Maybe this kind of sort would only need some extra logic?
I think it would be a good feature.
@rok what do you think?
[-]`list_sort`[/-][+][C++][Python]`list_sort` - sorting individual ListScalars[/+]raisadz commentedon Nov 6, 2025
Hello, would you be also willing to consider adding aggregate functions to the list methods:
list_min,list_max,list_mean,list_median, andlist_sum? ThanksMarcoGorelli commentedon Nov 6, 2025
thanks @AlenkaF !
Just to clarify the request - I'm hoping for an efficient function like
which does the whole thing in C++, rather than extracting each row as a scalar and sorting each one individually myself (especially from Python!)
AlenkaF commentedon Nov 6, 2025
Of course! This clarification was needed though, thanks =)
I was thinking we might not need a separate kernel in C++ but do it efficiently with existing ones. Not sure though!
I would personally support additions of new kernels but I have to point out this is an effort that would need developer help from the community (meaning, contributions are most welcome! :) )
AlenkaF commentedon Nov 7, 2025
After talking to Rok and looking at the docs I understand better that sorting values "per row" in a list array would need a new kernel due to having all values of the list stored in one buffer. The kernel would need to take offsets into account and sort values in separate intervals.
rok commentedon Nov 7, 2025
I'm slightly surprised we don't have this yet, not even as an aggregation. It would be nice to add it as a C++ kernel indeed.
@raisadz for the min/max/mean/median/sum, you could use aggregation kernels, though I'm sure this can be done more efficiently working directly on the ListArray:
[-][C++][Python]`list_sort` - sorting individual ListScalars[/-][+][C++][Python] `list_sort` - sorting individual ListScalars[/+]raisadz commentedon Nov 10, 2025
Thanks a lot for pointing me to the aggregation kernels @rok, it seems to work well for my task!
rok commentedon Nov 10, 2025
Great to hear @raisadz ! Do keep in mind aggregate kernels here might be less optimal than what's possible to do operating directly on a
ListArrayand it's perhaps still worth investigating c++ kernels for your usecase.github-actions commentedon Nov 11, 2026
This issue has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this issue will be closed in 14 days. If this improvement is still desired but has no current owner, please add the 'Status: needs champion' label.
rok commentedon Dec 2, 2026
@MarcoGorelli is this something that would be useful?
MarcoGorelli commentedon Dec 4, 2026
if it would be more efficient than the workaround suggested in #48060 (comment), then yes, definitely