Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate pylibcudf lists gathering #16170

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial commit
  • Loading branch information
Matt711 committed Jul 2, 2024
commit 286dd3c2d4564da77c50afa1d263a36806969fc4
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/pylibcudf/lists.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ cpdef Column contains_nulls(Column)

cpdef Column index_of(Column, ColumnOrScalar, bool)

cpdef Column segmented_gather(Column, Column, bool)
cpdef Column segmented_gather(Column, Column)
32 changes: 29 additions & 3 deletions python/cudf/cudf/_lib/pylibcudf/lists.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from cudf._lib.pylibcudf.libcudf.column.column cimport column
from cudf._lib.pylibcudf.libcudf.lists cimport (
contains as cpp_contains,
explode as cpp_explode,
gather as cpp_gather,
)
from cudf._lib.pylibcudf.libcudf.lists.combine cimport (
concatenate_list_elements as cpp_concatenate_list_elements,
Expand Down Expand Up @@ -208,7 +209,32 @@ cpdef Column index_of(Column input, ColumnOrScalar search_key, bool find_first_o
return Column.from_libcudf(move(c_result))


cpdef Column segmented_gather(Column input, Column gather_map_list, bool check_bounds):
"""column with elements in list of rows gathered based on gather_map_list
cpdef Column segmented_gather(Column input, Column gather_map_list):
"""Create a column with elements gathered based on the indices in gather_map_list

For details, see :cpp:func:`segmented_gather`.

Parameters
----------
input : Column
The input column.
gather_map_list : Column
The indices of the lists column to gather.

Returns
-------
Column
A new Column with elements in list of rows
gathered based on gather_map_list
"""
pass

cdef unique_ptr[column] c_result
cdef ListColumnView list_view1 = input.list_view()
cdef ListColumnView list_view2 = gather_map_list.list_view()

with nogil:
c_result = move(cpp_gather.segmented_gather(
list_view1.view(),
list_view2.view(),
))
return Column.from_libcudf(move(c_result))
14 changes: 14 additions & 0 deletions python/cudf/cudf/pylibcudf_tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,17 @@ def test_index_of_list_column(test_data, column):
expect = pa.array(column[1], type=pa.int32())

assert_column_eq(expect, res)


def test_segmented_gather(test_data):
list_column1 = test_data[0][0]
list_column2 = test_data[0][1]

plc_column1 = plc.interop.from_arrow(pa.array(list_column1))
plc_column2 = plc.interop.from_arrow(pa.array(list_column2))

res = plc.lists.segmented_gather(plc_column2, plc_column1)

expect = pa.array([[8, 9], [14], [0], [0, 0]])

assert_column_eq(expect, res)
Loading