Skip to content

Commit

Permalink
Implement __eq__ and __hash__ for Aggregation objects
Browse files Browse the repository at this point in the history
Use the matching C++ implementations for OAOO.
  • Loading branch information
wence- committed May 13, 2024
1 parent 18be236 commit c0089bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/cudf/cudf/_lib/cpp/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
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 @@ -77,6 +77,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

0 comments on commit c0089bb

Please sign in to comment.