-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate lists/combine to pylibcudf (#15928)
Part of #15162. concatenate_rows, concatenate_list_elements Authors: - Matthew Murray (https://github.com/Matt711) Approvers: - Vyas Ramasubramani (https://github.com/vyasr) - Thomas Li (https://github.com/lithomas1) URL: #15928
- Loading branch information
Showing
4 changed files
with
127 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
from libcpp cimport bool | ||
|
||
from cudf._lib.pylibcudf.libcudf.types cimport size_type | ||
|
||
from .column cimport Column | ||
from .table cimport Table | ||
|
||
|
||
cpdef Table explode_outer(Table, size_type explode_column_idx) | ||
|
||
cpdef Column concatenate_rows(Table) | ||
|
||
cpdef Column concatenate_list_elements(Column, bool dropna) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) 2024, NVIDIA CORPORATION. | ||
|
||
import pyarrow as pa | ||
import pytest | ||
from utils import assert_column_eq | ||
|
||
from cudf._lib import pylibcudf as plc | ||
|
||
|
||
def test_concatenate_rows(): | ||
test_data = [[[0, 1], [2], [5], [6, 7]], [[8], [9], [], [13, 14, 15]]] | ||
|
||
arrow_tbl = pa.Table.from_arrays(test_data, names=["a", "b"]) | ||
plc_tbl = plc.interop.from_arrow(arrow_tbl) | ||
|
||
res = plc.lists.concatenate_rows(plc_tbl) | ||
|
||
expect = pa.array([pair[0] + pair[1] for pair in zip(*test_data)]) | ||
|
||
assert_column_eq(expect, res) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_data, dropna, expected", | ||
[ | ||
( | ||
[[[1, 2], [3, 4], [5]], [[6], None, [7, 8, 9]]], | ||
False, | ||
[[1, 2, 3, 4, 5], None], | ||
), | ||
( | ||
[[[1, 2], [3, 4], [5, None]], [[6], [None], [7, 8, 9]]], | ||
True, | ||
[[1, 2, 3, 4, 5, None], [6, None, 7, 8, 9]], | ||
), | ||
], | ||
) | ||
def test_concatenate_list_elements(test_data, dropna, expected): | ||
arr = pa.array(test_data) | ||
plc_column = plc.interop.from_arrow(arr) | ||
|
||
res = plc.lists.concatenate_list_elements(plc_column, dropna) | ||
|
||
expect = pa.array(expected) | ||
|
||
assert_column_eq(expect, res) |