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

Remove cudf._lib.merge in favor of inlining pylibcudf #17370

Merged
merged 10 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ set(cython_sources
filling.pyx
groupby.pyx
interop.pyx
merge.pyx
orc.pyx
parquet.pyx
reduce.pyx
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/_lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
filling,
groupby,
interop,
merge,
nvtext,
orc,
parquet,
Expand Down
47 changes: 0 additions & 47 deletions python/cudf/cudf/_lib/merge.pyx

This file was deleted.

50 changes: 39 additions & 11 deletions python/cudf/cudf/core/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import numpy as np
import pandas as pd

import pylibcudf as plc

import cudf
from cudf._lib.column import Column
from cudf._lib.transform import one_hot_encode
from cudf._lib.types import size_type_dtype
from cudf.api.extensions import no_default
Expand Down Expand Up @@ -941,21 +944,46 @@ def _merge_sorted(
idx + objs[0].index.nlevels for idx in key_columns_indices
]

columns = [
[
*(obj.index._columns if not ignore_index else ()),
*obj._columns,
]
columns = (
itertools.chain(obj.index._columns, obj._columns)
if not ignore_index
else obj._columns
for obj in objs
)

input_tables = [
plc.Table([col.to_pylibcudf(mode="read") for col in source_columns])
for source_columns in columns
]

num_keys = len(key_columns_indices)

column_order = (
plc.types.Order.ASCENDING if ascending else plc.types.Order.DESCENDING
)

if not ascending:
na_position = "last" if na_position == "first" else "first"

null_precedence = (
plc.types.NullOrder.BEFORE
if na_position == "first"
else plc.types.NullOrder.AFTER
)

plc_table = plc.merge.merge(
input_tables,
key_columns_indices,
[column_order] * num_keys,
[null_precedence] * num_keys,
)

result_columns = [
Column.from_pylibcudf(col) for col in plc_table.columns()
]

return objs[0]._from_columns_like_self(
cudf._lib.merge.merge_sorted(
input_columns=columns,
key_columns_indices=key_columns_indices,
ascending=ascending,
na_position=na_position,
),
result_columns,
column_names=objs[0]._column_names,
index_names=None if ignore_index else objs[0]._index_names,
)
Expand Down
Loading