Skip to content

Commit fb7c1c2

Browse files
author
MarcoGorelli
committed
use built-in non-hashable message
1 parent f3929d9 commit fb7c1c2

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

pandas/core/generic.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,16 +1872,10 @@ def _drop_labels_or_levels(self, keys, axis: int = 0):
18721872
# ----------------------------------------------------------------------
18731873
# Iteration
18741874

1875-
def _hash(self) -> int:
1876-
raise TypeError(
1877-
f"{repr(type(self).__name__)} objects are mutable, "
1878-
f"thus they cannot be hashed"
1879-
)
1880-
18811875
# https://github.com/python/typeshed/issues/2148#issuecomment-520783318
18821876
# Incompatible types in assignment (expression has type "None", base class
18831877
# "object" defined the type as "Callable[[object], int]")
1884-
__hash__: None = _hash # type: ignore[assignment]
1878+
__hash__: None # type: ignore[assignment]
18851879

18861880
def __iter__(self):
18871881
"""

pandas/tests/frame/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_not_hashable(self):
9191
empty_frame = DataFrame()
9292

9393
df = DataFrame([1])
94-
msg = "'DataFrame' objects are mutable, thus they cannot be hashed"
94+
msg = "unhashable type: 'DataFrame'"
9595
with pytest.raises(TypeError, match=msg):
9696
hash(df)
9797
with pytest.raises(TypeError, match=msg):

pandas/tests/series/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_index_tab_completion(self, index):
101101
def test_not_hashable(self):
102102
s_empty = Series(dtype=object)
103103
s = Series([1])
104-
msg = "'Series' objects are mutable, thus they cannot be hashed"
104+
msg = "unhashable type: 'Series'"
105105
with pytest.raises(TypeError, match=msg):
106106
hash(s_empty)
107107
with pytest.raises(TypeError, match=msg):

0 commit comments

Comments
 (0)