Skip to content

Commit

Permalink
OAOO __eq__ on DataType
Browse files Browse the repository at this point in the history
The C++ data_type type implements operator==, so we should use it in
Cython to avoid the definitions ever going out of sync.
  • Loading branch information
wence- committed May 13, 2024
1 parent 149253b commit 18be236
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions python/cudf/cudf/_lib/cpp/types.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/_lib/pylibcudf/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 == (<DataType>other).c_obj
)

@staticmethod
cdef DataType from_libcudf(data_type dt):
Expand Down

0 comments on commit 18be236

Please sign in to comment.