Skip to content

Commit

Permalink
Maintain consistent hash values for equal objects
Browse files Browse the repository at this point in the history
  • Loading branch information
galipremsagar committed Jan 6, 2021
1 parent bdc5c21 commit 6ccd860
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/lists.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2021, NVIDIA CORPORATION.

import pickle

Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/dtypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2021, NVIDIA CORPORATION.

import decimal
import pickle
Expand Down Expand Up @@ -166,7 +166,7 @@ def __repr__(self):
return f"ListDtype({self.element_type})"

def __hash__(self):
return id(self)
return hash(self._typ)


class StructDtype(ExtensionDtype):
Expand Down
13 changes: 12 additions & 1 deletion python/cudf/cudf/tests/test_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2021, NVIDIA CORPORATION.

import pandas as pd
import pyarrow as pa
Expand Down Expand Up @@ -78,3 +78,14 @@ def test_list_to_pandas_nullable_true():
expected = pd.DataFrame({"a": pd.Series([[1, 2, 3]])})

assert_eq(actual, expected)


def test_listdtype_hash():
a = cudf.core.dtypes.ListDtype("int64")
b = cudf.core.dtypes.ListDtype("int64")

assert hash(a) == hash(b)

c = cudf.core.dtypes.ListDtype("int32")

assert hash(a) != hash(c)

0 comments on commit 6ccd860

Please sign in to comment.