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

Move all core types to using enum class in Cython #14876

Merged
merged 3 commits into from
Jan 25, 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
83 changes: 38 additions & 45 deletions python/cudf/cudf/_lib/cpp/types.pxd
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

from libc.stdint cimport int32_t, uint32_t
from libcpp cimport bool


cdef extern from "cudf/types.hpp" namespace "cudf" nogil:
# The declaration below is to work around
# https://github.com/cython/cython/issues/5637
"""
#define __PYX_ENUM_CLASS_DECL enum
"""
ctypedef int32_t size_type
ctypedef uint32_t bitmask_type
ctypedef uint32_t char_utf8

ctypedef enum mask_state:
UNALLOCATED "cudf::mask_state::UNALLOCATED"
UNINITIALIZED "cudf::mask_state::UNINITIALIZED"
ALL_VALID "cudf::mask_state::ALL_VALID"
ALL_NULL "cudf::mask_state::ALL_NULL"
# A Hack to let cython compile with __int128_t symbol
# https://stackoverflow.com/a/27609033
ctypedef int int128 "__int128_t"

ctypedef enum order "cudf::order":
ASCENDING "cudf::order::ASCENDING"
DESCENDING "cudf::order::DESCENDING"
cpdef enum class mask_state(int32_t):
UNALLOCATED
UNINITIALIZED
ALL_VALID
ALL_NULL

ctypedef enum null_order "cudf::null_order":
AFTER "cudf::null_order::AFTER"
BEFORE "cudf::null_order::BEFORE"
cpdef enum class order(bool):
ASCENDING
DESCENDING

ctypedef enum sorted "cudf::sorted":
NO "cudf::sorted::NO"
YES "cudf::sorted::YES"
cpdef enum class null_order(bool):
AFTER
BEFORE

cpdef enum class sorted(bool):
NO
YES

cdef cppclass order_info:
sorted is_sorted
order ordering
null_order null_ordering

ctypedef enum null_policy "cudf::null_policy":
EXCLUDE "cudf::null_policy::EXCLUDE"
INCLUDE "cudf::null_policy::INCLUDE"
cpdef enum class null_policy(bool):
EXCLUDE
INCLUDE

ctypedef enum nan_policy "cudf::nan_policy":
NAN_IS_NULL "cudf::nan_policy::NAN_IS_NULL"
NAN_IS_VALID "cudf::nan_policy::NAN_IS_VALID"
cpdef enum class nan_policy(bool):
NAN_IS_NULL
NAN_IS_VALID

ctypedef enum null_equality "cudf::null_equality":
EQUAL "cudf::null_equality::EQUAL"
UNEQUAL "cudf::null_equality::UNEQUAL"
cpdef enum class null_equality(bool):
EQUAL
UNEQUAL

ctypedef enum nan_equality "cudf::nan_equality":
# These names differ from the C++ names due to Cython warnings if
# "UNEQUAL" is declared by both null_equality and nan_equality.
ALL_EQUAL "cudf::nan_equality::ALL_EQUAL"
NANS_UNEQUAL "cudf::nan_equality::UNEQUAL"
cpdef enum class nan_equality(bool):
ALL_EQUAL
UNEQUAL

cpdef enum class type_id(int32_t):
EMPTY
Expand Down Expand Up @@ -93,14 +91,9 @@ cdef extern from "cudf/types.hpp" namespace "cudf" nogil:
type_id id() except +
int32_t scale() except +

cdef extern from "cudf/types.hpp" namespace "cudf" nogil:
ctypedef enum interpolation:
LINEAR "cudf::interpolation::LINEAR"
LOWER "cudf::interpolation::LOWER"
HIGHER "cudf::interpolation::HIGHER"
MIDPOINT "cudf::interpolation::MIDPOINT"
NEAREST "cudf::interpolation::NEAREST"

# A Hack to let cython compile with __int128_t symbol
# https://stackoverflow.com/a/27609033
ctypedef int int128 "__int128_t"
cpdef enum class interpolation(int32_t):
LINEAR
LOWER
HIGHER
MIDPOINT
NEAREST
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/lists.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Copyright (c) 2021-2024, NVIDIA CORPORATION.

from cudf.core.buffer import acquire_spill_lock

Expand Down Expand Up @@ -84,7 +84,7 @@ def distinct(Column col, bool nulls_equal, bool nans_all_equal):
null_equality.EQUAL if nulls_equal else null_equality.UNEQUAL
)
cdef nan_equality c_nans_equal = (
nan_equality.ALL_EQUAL if nans_all_equal else nan_equality.NANS_UNEQUAL
nan_equality.ALL_EQUAL if nans_all_equal else nan_equality.UNEQUAL
)

cdef unique_ptr[column] c_result
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/_lib/stream_compaction.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

from cudf.core.buffer import acquire_spill_lock

Expand Down Expand Up @@ -209,7 +209,7 @@ def distinct_indices(
cdef nan_equality cpp_nans_equal = (
nan_equality.ALL_EQUAL
if nans_equal
else nan_equality.NANS_UNEQUAL
else nan_equality.UNEQUAL
)
cdef table_view source = table_view_from_columns(columns)
cdef unique_ptr[column] c_result
Expand Down
Loading