Skip to content

Commit c3a5997

Browse files
committed
fixes
1 parent 7232386 commit c3a5997

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

pandas/core/dtypes/common.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ def _validate_date_like_dtype(dtype) -> None:
17321732
)
17331733

17341734

1735-
def validate_all_hashable(*args) -> None:
1735+
def validate_all_hashable(*args, name: str=None) -> None:
17361736
"""
17371737
Return None if all args are hashable, else raise a TypeError.
17381738
@@ -1752,7 +1752,10 @@ def validate_all_hashable(*args) -> None:
17521752
TypeError: All elements must be hashable
17531753
"""
17541754
if not all(is_hashable(arg) for arg in args):
1755-
raise TypeError("All elements must be hashable")
1755+
if name:
1756+
raise TypeError(f"{name} must be a hashable type")
1757+
else:
1758+
raise TypeError("All elements must be hashable")
17561759

17571760

17581761
def pandas_dtype(dtype) -> DtypeObj:

pandas/core/indexes/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ def _validate_names(self, name=None, names=None, deep: bool = False) -> List[Lab
12111211
)
12121212

12131213
# All items in 'new_names' need to be hashable
1214-
validate_all_hashable(*new_names)
1214+
validate_all_hashable(*new_names, name=f"{type(self).__name__}.name")
12151215

12161216
return new_names
12171217

@@ -1241,7 +1241,7 @@ def _set_names(self, values, level=None):
12411241

12421242
# GH 20527
12431243
# All items in 'name' need to be hashable:
1244-
validate_all_hashable(*values)
1244+
validate_all_hashable(*values, name=f"{type(self).__name__}.name")
12451245

12461246
self._name = values[0]
12471247

pandas/tests/indexes/multi/test_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_copy_names():
7979
with pytest.raises(ValueError, match="Length of new names must be 2, got 1"):
8080
multi_idx.copy(names=["mario"])
8181

82-
with pytest.raises(TypeError, match="All elements must be hashable"):
82+
with pytest.raises(TypeError, match="MultiIndex.name must be a hashable type"):
8383
multi_idx.copy(names=[["mario"], ["luigi"]])
8484

8585

0 commit comments

Comments
 (0)