From 18be2364b50ceeda6c3f1caf20d930ebe9b8eb4e Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Tue, 16 Apr 2024 16:03:35 +0000 Subject: [PATCH] OAOO __eq__ on DataType The C++ data_type type implements operator==, so we should use it in Cython to avoid the definitions ever going out of sync. --- python/cudf/cudf/_lib/cpp/types.pxd | 5 +++-- python/cudf/cudf/_lib/pylibcudf/types.pyx | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/python/cudf/cudf/_lib/cpp/types.pxd b/python/cudf/cudf/_lib/cpp/types.pxd index 13aebdff726..8e94ec296cf 100644 --- a/python/cudf/cudf/_lib/cpp/types.pxd +++ b/python/cudf/cudf/_lib/cpp/types.pxd @@ -88,8 +88,9 @@ cdef extern from "cudf/types.hpp" namespace "cudf" nogil: data_type(const data_type&) except + data_type(type_id id) except + data_type(type_id id, int32_t scale) except + - type_id id() except + - int32_t scale() except + + type_id id() noexcept + int32_t scale() noexcept + bool operator==(const data_type&, const data_type&) noexcept cpdef enum class interpolation(int32_t): LINEAR diff --git a/python/cudf/cudf/_lib/pylibcudf/types.pyx b/python/cudf/cudf/_lib/pylibcudf/types.pyx index baf92223714..f7bd5e94c18 100644 --- a/python/cudf/cudf/_lib/pylibcudf/types.pyx +++ b/python/cudf/cudf/_lib/pylibcudf/types.pyx @@ -47,9 +47,9 @@ cdef class DataType: return self.c_obj.scale() def __eq__(self, other): - if not isinstance(other, DataType): - return False - return self.id() == other.id() and self.scale() == other.scale() + return type(self) is type(other) and ( + self.c_obj == (other).c_obj + ) @staticmethod cdef DataType from_libcudf(data_type dt):