Skip to content

Commit 5e1116d

Browse files
authored
Remove cudf._lib.utils usage in favor of pylibcudf (#2082)
In anticipation of this downstream cuDF PR removing some functionality in `cudf._lib.utils` rapidsai/cudf#17586, this PR replaces that usage with equivalent usage from the stable `pylibcudf` ## By Submitting this PR I confirm: - I am familiar with the [Contributing Guidelines](https://github.com/nv-morpheus/Morpheus/blob/main/docs/source/developer_guide/contributing.md). - When the PR is ready for review, new or existing tests cover these changes. - When the PR is ready for review, the documentation is up to date with these changes. Authors: - Matthew Roeschke (https://github.com/mroeschke) - David Gardner (https://github.com/dagardner-nv) Approvers: - David Gardner (https://github.com/dagardner-nv) URL: #2082
1 parent 5f178ef commit 5e1116d

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

python/morpheus/morpheus/_lib/cudf_helpers.pyx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import itertools
17+
1618
import cudf
19+
from cudf.core.column import ColumnBase
1720
from cudf.core.dtypes import StructDtype
1821

1922
from libcpp.string cimport string
@@ -26,8 +29,6 @@ from pylibcudf.libcudf.table.table_view cimport table_view
2629
from pylibcudf.libcudf.types cimport size_type
2730

2831
from cudf._lib.column cimport Column
29-
from cudf._lib.utils cimport data_from_unique_ptr
30-
from cudf._lib.utils cimport table_view_from_table
3132

3233
##### THE FOLLOWING CODE IS COPIED FROM CUDF AND SHOULD BE REMOVED WHEN UPDATING TO cudf>=24.12 #####
3334
# see https://github.com/rapidsai/cudf/pull/17193 for details
@@ -39,6 +40,7 @@ cimport pylibcudf.libcudf.copying as cpp_copying
3940
from pylibcudf.libcudf.column.column_view cimport column_view
4041
from libcpp.memory cimport make_unique, unique_ptr
4142
from pylibcudf.libcudf.scalar.scalar cimport scalar
43+
from pylibcudf cimport Table as plc_Table
4244
from cudf._lib.scalar cimport DeviceScalar
4345

4446
# imports needed for from_column_view_with_fix
@@ -289,8 +291,35 @@ cdef public api:
289291
index_names = schema_infos[0:index_col_count] if index_col_count > 0 else None
290292
column_names = schema_infos[index_col_count:]
291293

292-
data, index = data_from_unique_ptr(move(table.tbl), column_names=column_names, index_names=index_names)
294+
plc_table = plc_Table.from_libcudf(move(table.tbl))
293295

296+
if index_names is None:
297+
index = None
298+
data = {
299+
col_name: ColumnBase.from_pylibcudf(col)
300+
for col_name, col in zip(
301+
column_names, plc_table.columns()
302+
)
303+
}
304+
else:
305+
result_columns = [
306+
ColumnBase.from_pylibcudf(col)
307+
for col in plc_table.columns()
308+
]
309+
index = cudf.Index._from_data(
310+
dict(
311+
zip(
312+
index_names,
313+
result_columns[: len(index_names)],
314+
)
315+
)
316+
)
317+
data = dict(
318+
zip(
319+
column_names,
320+
result_columns[len(index_names) :],
321+
)
322+
)
294323
df = cudf.DataFrame._from_data(data, index)
295324

296325
# Update the struct field names after the DataFrame is created
@@ -356,7 +385,13 @@ cdef public api:
356385

357386
cdef vector[string] temp_col_names = get_column_names(table, True)
358387

359-
cdef table_view input_table_view = table_view_from_table(table, ignore_index=False)
388+
cdef plc_Table plc_table = plc_Table(
389+
[
390+
col.to_pylibcudf(mode="read")
391+
for col in itertools.chain(table.index._columns, table._columns)
392+
]
393+
)
394+
cdef table_view input_table_view = plc_table.view()
360395
cdef vector[string] index_names
361396
cdef vector[string] column_names
362397

0 commit comments

Comments
 (0)