Skip to content

Commit

Permalink
Remove cudf._lib.scalar in favor of pylibcudf (#17701)
Browse files Browse the repository at this point in the history
This PR changes `cudf.Scalar.device_scalar` to be a `pylibcudf.Scalar` object instead of a `cudf._lib.scalar.DeviceScalar`.
 
Most of the conversion logic previously in `cudf._lib.scalar.DeviceScalar` now lives in `python/cudf/cudf/core/scalar.py`

Some tests that exercised behaviors of `cudf.Scalar.device_scalar` when it was a `cudf._lib.scalar.DeviceScalar` were modified/removed.

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #17701
  • Loading branch information
mroeschke authored Jan 24, 2025
1 parent e9bfab5 commit 9f3cb65
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 454 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# the License.
# =============================================================================

set(cython_sources column.pyx scalar.pyx strings_udf.pyx)
set(cython_sources column.pyx strings_udf.pyx)
set(linked_libraries cudf::cudf)

rapids_cython_create_modules(
Expand Down
18 changes: 9 additions & 9 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ from libcpp.vector cimport vector

from rmm.pylibrmm.device_buffer cimport DeviceBuffer

from pylibcudf cimport DataType as plc_DataType, Column as plc_Column
from pylibcudf cimport (
DataType as plc_DataType,
Column as plc_Column,
Scalar as plc_Scalar,
)
cimport pylibcudf.libcudf.copying as cpp_copying
cimport pylibcudf.libcudf.types as libcudf_types
cimport pylibcudf.libcudf.unary as libcudf_unary
Expand All @@ -45,8 +49,6 @@ from pylibcudf.libcudf.column.column_view cimport column_view
from pylibcudf.libcudf.lists.lists_column_view cimport lists_column_view
from pylibcudf.libcudf.scalar.scalar cimport scalar

from cudf._lib.scalar cimport DeviceScalar


cdef get_element(column_view col_view, size_type index):

Expand All @@ -55,10 +57,8 @@ cdef get_element(column_view col_view, size_type index):
c_output = move(
cpp_copying.get_element(col_view, index)
)

return DeviceScalar.from_unique_ptr(
move(c_output), dtype=dtype_from_column_view(col_view)
)
plc_scalar = plc_Scalar.from_libcudf(move(c_output))
return pylibcudf.interop.to_arrow(plc_scalar).as_py()


def dtype_from_pylibcudf_column(plc_Column col not None):
Expand Down Expand Up @@ -767,7 +767,7 @@ cdef class Column:
base_nbytes = 0
else:
chars_size = get_element(
offset_child_column, offset_child_column.size()-1).value
offset_child_column, offset_child_column.size()-1)
base_nbytes = chars_size

if data_ptr:
Expand Down Expand Up @@ -908,6 +908,6 @@ cdef class Column:
def from_scalar(py_val, size_type size):
return Column.from_pylibcudf(
pylibcudf.Column.from_scalar(
py_val.device_value.c_value, size
py_val.device_value, size
)
)
22 changes: 0 additions & 22 deletions python/cudf/cudf/_lib/scalar.pxd

This file was deleted.

243 changes: 0 additions & 243 deletions python/cudf/cudf/_lib/scalar.pyx

This file was deleted.

4 changes: 3 additions & 1 deletion python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import pyarrow as pa
from pandas.api import types as pd_types

import pylibcudf as plc

import cudf
from cudf.core._compat import PANDAS_LT_300
from cudf.core.dtypes import ( # noqa: F401
Expand Down Expand Up @@ -143,8 +145,8 @@ def is_scalar(val):
val,
(
cudf.Scalar,
cudf._lib.scalar.DeviceScalar,
cudf.core.tools.datetimes.DateOffset,
plc.Scalar,
pa.Scalar,
),
) or (
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/_internals/binaryop.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def binaryop(
plc.binaryop.binary_operation(
lhs.to_pylibcudf(mode="read")
if isinstance(lhs, Column)
else lhs.device_value.c_value,
else lhs.device_value,
rhs.to_pylibcudf(mode="read")
if isinstance(rhs, Column)
else rhs.device_value.c_value,
else rhs.device_value,
plc.binaryop.BinaryOperator[op],
dtype_to_pylibcudf_type(dtype),
)
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/_internals/copying.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
# Copyright (c) 2020-2025, NVIDIA CORPORATION.
from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down Expand Up @@ -67,7 +67,7 @@ def scatter(
plc_tbl = plc.copying.scatter(
plc.Table([col.to_pylibcudf(mode="read") for col in sources]) # type: ignore[union-attr]
if isinstance(sources[0], cudf._lib.column.Column)
else [slr.device_value.c_value for slr in sources], # type: ignore[union-attr]
else [slr.device_value for slr in sources], # type: ignore[union-attr]
scatter_map.to_pylibcudf(mode="read"),
plc.Table([col.to_pylibcudf(mode="read") for col in target_columns]),
)
Expand Down
Loading

0 comments on commit 9f3cb65

Please sign in to comment.