From b400de203cec985d141c00c883dda192c1c6d055 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Thu, 25 Jan 2024 01:45:50 +0000 Subject: [PATCH 1/3] Migrate all core type enums except nan_equality --- python/cudf/cudf/_lib/cpp/types.pxd | 65 +++++++++++++---------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/python/cudf/cudf/_lib/cpp/types.pxd b/python/cudf/cudf/_lib/cpp/types.pxd index 14bf8a83de0..82b262f95e3 100644 --- a/python/cudf/cudf/_lib/cpp/types.pxd +++ b/python/cudf/cudf/_lib/cpp/types.pxd @@ -1,52 +1,47 @@ -# Copyright (c) 2020-2023, NVIDIA CORPORATION. +# Copyright (c) 2020-2024, NVIDIA CORPORATION. from libc.stdint cimport int32_t, uint32_t 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" + cpdef enum class mask_state: + UNALLOCATED + UNINITIALIZED + ALL_VALID + ALL_NULL - ctypedef enum order "cudf::order": - ASCENDING "cudf::order::ASCENDING" - DESCENDING "cudf::order::DESCENDING" + cpdef enum class order: + ASCENDING + DESCENDING - ctypedef enum null_order "cudf::null_order": - AFTER "cudf::null_order::AFTER" - BEFORE "cudf::null_order::BEFORE" + cpdef enum class null_order: + AFTER + BEFORE - ctypedef enum sorted "cudf::sorted": - NO "cudf::sorted::NO" - YES "cudf::sorted::YES" + cpdef enum class sorted: + 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: + 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: + 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: + EQUAL + UNEQUAL ctypedef enum nan_equality "cudf::nan_equality": # These names differ from the C++ names due to Cython warnings if @@ -94,12 +89,12 @@ cdef extern from "cudf/types.hpp" namespace "cudf" nogil: 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" + cpdef enum class interpolation: + LINEAR + LOWER + HIGHER + MIDPOINT + NEAREST # A Hack to let cython compile with __int128_t symbol # https://stackoverflow.com/a/27609033 From fef235291553063f6d7040ae8d2fdcc543a5eb4a Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Thu, 25 Jan 2024 01:48:01 +0000 Subject: [PATCH 2/3] Migrate nan_equality --- python/cudf/cudf/_lib/cpp/types.pxd | 8 +++----- python/cudf/cudf/_lib/lists.pyx | 4 ++-- python/cudf/cudf/_lib/stream_compaction.pyx | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/python/cudf/cudf/_lib/cpp/types.pxd b/python/cudf/cudf/_lib/cpp/types.pxd index 82b262f95e3..8d900024bd3 100644 --- a/python/cudf/cudf/_lib/cpp/types.pxd +++ b/python/cudf/cudf/_lib/cpp/types.pxd @@ -43,11 +43,9 @@ cdef extern from "cudf/types.hpp" namespace "cudf" nogil: 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: + ALL_EQUAL + UNEQUAL cpdef enum class type_id(int32_t): EMPTY diff --git a/python/cudf/cudf/_lib/lists.pyx b/python/cudf/cudf/_lib/lists.pyx index 199641fd2ce..f76d7a9a388 100644 --- a/python/cudf/cudf/_lib/lists.pyx +++ b/python/cudf/cudf/_lib/lists.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023, NVIDIA CORPORATION. +# Copyright (c) 2021-2024, NVIDIA CORPORATION. from cudf.core.buffer import acquire_spill_lock @@ -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 diff --git a/python/cudf/cudf/_lib/stream_compaction.pyx b/python/cudf/cudf/_lib/stream_compaction.pyx index 9b22728d2f0..d7725e8df94 100644 --- a/python/cudf/cudf/_lib/stream_compaction.pyx +++ b/python/cudf/cudf/_lib/stream_compaction.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2023, NVIDIA CORPORATION. +# Copyright (c) 2020-2024, NVIDIA CORPORATION. from cudf.core.buffer import acquire_spill_lock @@ -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 From e50c4b774a7dd9b29115622f826ba4ff8cae03e4 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Thu, 25 Jan 2024 01:51:44 +0000 Subject: [PATCH 3/3] Add all base types and do some minor cleanup --- python/cudf/cudf/_lib/cpp/types.pxd | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/python/cudf/cudf/_lib/cpp/types.pxd b/python/cudf/cudf/_lib/cpp/types.pxd index 8d900024bd3..13aebdff726 100644 --- a/python/cudf/cudf/_lib/cpp/types.pxd +++ b/python/cudf/cudf/_lib/cpp/types.pxd @@ -1,6 +1,7 @@ # 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: @@ -8,21 +9,25 @@ cdef extern from "cudf/types.hpp" namespace "cudf" nogil: ctypedef uint32_t bitmask_type ctypedef uint32_t char_utf8 - cpdef enum class mask_state: + # A Hack to let cython compile with __int128_t symbol + # https://stackoverflow.com/a/27609033 + ctypedef int int128 "__int128_t" + + cpdef enum class mask_state(int32_t): UNALLOCATED UNINITIALIZED ALL_VALID ALL_NULL - cpdef enum class order: + cpdef enum class order(bool): ASCENDING DESCENDING - cpdef enum class null_order: + cpdef enum class null_order(bool): AFTER BEFORE - cpdef enum class sorted: + cpdef enum class sorted(bool): NO YES @@ -31,19 +36,19 @@ cdef extern from "cudf/types.hpp" namespace "cudf" nogil: order ordering null_order null_ordering - cpdef enum class null_policy: + cpdef enum class null_policy(bool): EXCLUDE INCLUDE - cpdef enum class nan_policy: + cpdef enum class nan_policy(bool): NAN_IS_NULL NAN_IS_VALID - cpdef enum class null_equality: + cpdef enum class null_equality(bool): EQUAL UNEQUAL - cpdef enum class nan_equality: + cpdef enum class nan_equality(bool): ALL_EQUAL UNEQUAL @@ -86,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: - cpdef enum class interpolation: + cpdef enum class interpolation(int32_t): LINEAR LOWER HIGHER MIDPOINT NEAREST - - # A Hack to let cython compile with __int128_t symbol - # https://stackoverflow.com/a/27609033 - ctypedef int int128 "__int128_t"