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

Defer to C++ equality and hashing for pylibcudf DataType and Aggregation objects #15732

Merged
merged 2 commits into from
May 16, 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
8 changes: 8 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/aggregation.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ cdef class Aggregation:
"Aggregations should not be constructed directly. Use one of the factories."
)

def __eq__(self, other):
return type(self) is type(other) and (
dereference(self.c_obj).is_equal(dereference((<Aggregation>other).c_obj))
)

def __hash__(self):
return dereference(self.c_obj).do_hash()

# TODO: Ideally we would include the return type here, but we need to do so
# in a way that Sphinx understands (currently have issues due to
# https://github.com/cython/cython/issues/5609).
Expand Down
3 changes: 3 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/libcudf/aggregation.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
from libc.stddef cimport size_t
from libc.stdint cimport int32_t
from libcpp cimport bool
from libcpp.memory cimport unique_ptr
Expand Down Expand Up @@ -51,6 +52,8 @@ cdef extern from "cudf/aggregation.hpp" namespace "cudf" nogil:
cdef cppclass aggregation:
Kind kind
unique_ptr[aggregation] clone()
size_t do_hash() noexcept
bool is_equal(const aggregation const) noexcept

cdef cppclass rolling_aggregation(aggregation):
pass
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/cudf/_lib/pylibcudf/libcudf/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
Loading