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

Use pylibcudf enums in cudf Python quantile #17287

Merged
merged 2 commits into from
Nov 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
28 changes: 4 additions & 24 deletions python/cudf/cudf/_lib/quantiles.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ from libcpp cimport bool
from libcpp.vector cimport vector

from cudf._lib.column cimport Column
from cudf._lib.types cimport (
underlying_type_t_interpolation,
underlying_type_t_sorted,
)

from cudf._lib.types import Interpolation

from pylibcudf.libcudf.types cimport interpolation, sorted

from cudf._lib.utils cimport columns_from_pylibcudf_table

Expand All @@ -28,17 +20,13 @@ def quantile(
Column ordered_indices,
bool exact,
):
cdef interpolation c_interp = <interpolation>(
<underlying_type_t_interpolation> Interpolation[interp.upper()]
)

return Column.from_pylibcudf(
plc.quantiles.quantile(
input.to_pylibcudf(mode="read"),
q,
c_interp,
plc.types.Interpolation[interp.upper()],
ordered_indices.to_pylibcudf(mode="read"),
<bool>exact
exact
)
)

Expand All @@ -51,22 +39,14 @@ def quantile_table(
list column_order,
list null_precedence,
):

cdef interpolation c_interp = <interpolation>(
<underlying_type_t_interpolation> interp
)
cdef sorted c_is_input_sorted = <sorted>(
<underlying_type_t_sorted> is_input_sorted
)

return columns_from_pylibcudf_table(
plc.quantiles.quantiles(
plc.Table([
c.to_pylibcudf(mode="read") for c in source_columns
]),
q,
c_interp,
c_is_input_sorted,
interp,
is_input_sorted,
column_order,
null_precedence
)
Expand Down
44 changes: 0 additions & 44 deletions python/cudf/cudf/_lib/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ cimport pylibcudf.libcudf.types as libcudf_types
from pylibcudf.libcudf.column.column_view cimport column_view
from pylibcudf.libcudf.lists.lists_column_view cimport lists_column_view

from cudf._lib.types cimport (
underlying_type_t_interpolation,
underlying_type_t_order,
underlying_type_t_sorted,
)

import pylibcudf

import cudf
Expand Down Expand Up @@ -151,44 +145,6 @@ datetime_unit_map = {
size_type_dtype = LIBCUDF_TO_SUPPORTED_NUMPY_TYPES[pylibcudf.types.SIZE_TYPE_ID]


class Interpolation(IntEnum):
LINEAR = (
<underlying_type_t_interpolation> libcudf_types.interpolation.LINEAR
)
LOWER = (
<underlying_type_t_interpolation> libcudf_types.interpolation.LOWER
)
HIGHER = (
<underlying_type_t_interpolation> libcudf_types.interpolation.HIGHER
)
MIDPOINT = (
<underlying_type_t_interpolation> libcudf_types.interpolation.MIDPOINT
)
NEAREST = (
<underlying_type_t_interpolation> libcudf_types.interpolation.NEAREST
)


class Order(IntEnum):
ASCENDING = <underlying_type_t_order> libcudf_types.order.ASCENDING
DESCENDING = <underlying_type_t_order> libcudf_types.order.DESCENDING


class Sorted(IntEnum):
YES = <underlying_type_t_sorted> libcudf_types.sorted.YES
NO = <underlying_type_t_sorted> libcudf_types.sorted.NO


class NullOrder(IntEnum):
BEFORE = <underlying_type_t_order> libcudf_types.null_order.BEFORE
AFTER = <underlying_type_t_order> libcudf_types.null_order.AFTER


class NullHandling(IntEnum):
INCLUDE = <underlying_type_t_null_policy> libcudf_types.null_policy.INCLUDE
EXCLUDE = <underlying_type_t_null_policy> libcudf_types.null_policy.EXCLUDE


cdef dtype_from_lists_column_view(column_view cv):
# lists_column_view have no default constructor, so we heap
# allocate it to get around Cython's limitation of requiring
Expand Down
12 changes: 6 additions & 6 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import pyarrow as pa
from typing_extensions import Self

import pylibcudf as plc

import cudf
from cudf import _lib as libcudf
from cudf.api.types import is_dtype_equal, is_scalar
Expand Down Expand Up @@ -789,15 +791,13 @@ def _quantile_table(
column_order=(),
null_precedence=(),
):
interpolation = libcudf.types.Interpolation[interpolation]
interpolation = plc.types.Interpolation[interpolation]

is_sorted = libcudf.types.Sorted["YES" if is_sorted else "NO"]
is_sorted = plc.types.Sorted["YES" if is_sorted else "NO"]

column_order = [libcudf.types.Order[key] for key in column_order]
column_order = [plc.types.Order[key] for key in column_order]

null_precedence = [
libcudf.types.NullOrder[key] for key in null_precedence
]
null_precedence = [plc.types.NullOrder[key] for key in null_precedence]

return self._from_columns_like_self(
libcudf.quantiles.quantile_table(
Expand Down
Loading