-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Hash and compare tuple subclasses as builtin tuples #59286
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
Changes from 9 commits
b66aed7
4f191e9
b5fdd7b
af11520
68cabf3
e800139
54009c3
190ac69
da68cd6
8ad9e4c
70d6511
2ef52eb
d596502
1554eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from collections import namedtuple | ||
from collections.abc import Generator | ||
from contextlib import contextmanager | ||
import re | ||
|
@@ -440,6 +441,27 @@ def test_nan_in_nested_tuple(self): | |
table.get_item(other) | ||
assert str(error.value) == str(other) | ||
|
||
def test_nan_in_namedtuple(self): | ||
T = namedtuple("T", ["x"]) | ||
nan1 = T(float("nan")) | ||
nan2 = T(float("nan")) | ||
assert nan1.x is not nan2.x | ||
table = ht.PyObjectHashTable() | ||
table.set_item(nan1, 42) | ||
assert table.get_item(nan2) == 42 | ||
|
||
def test_nan_in_nested_namedtuple(self): | ||
T = namedtuple("T", ["x", "y"]) | ||
nan1 = T(1, (2, (float("nan"),))) | ||
nan2 = T(1, (2, (float("nan"),))) | ||
other = T(1, 2) | ||
table = ht.PyObjectHashTable() | ||
table.set_item(nan1, 42) | ||
assert table.get_item(nan2) == 42 | ||
with pytest.raises(KeyError, match=None) as error: | ||
table.get_item(other) | ||
assert str(error.value) == str(other) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead could you use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be removed now that you added the match argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that makes more sense. I'll fix the other tests too while I'm at it. |
||
|
||
|
||
def test_hash_equal_tuple_with_nans(): | ||
a = (float("nan"), (float("nan"), float("nan"))) | ||
|
@@ -448,6 +470,14 @@ def test_hash_equal_tuple_with_nans(): | |
assert ht.objects_are_equal(a, b) | ||
|
||
|
||
def test_hash_equal_namedtuple_with_nans(): | ||
T = namedtuple("T", ["x", "y"]) | ||
a = T(float("nan"), (float("nan"), float("nan"))) | ||
b = T(float("nan"), (float("nan"), float("nan"))) | ||
assert ht.object_hash(a) == ht.object_hash(b) | ||
assert ht.objects_are_equal(a, b) | ||
|
||
|
||
def test_get_labels_groupby_for_Int64(writable): | ||
table = ht.Int64HashTable() | ||
vals = np.array([1, 2, -1, 2, 1, -1], dtype=np.int64) | ||
|
Uh oh!
There was an error while loading. Please reload this page.