Skip to content

Commit 430d0cc

Browse files
committed
add test for validate_all_hashable
1 parent 77c28a5 commit 430d0cc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

pandas/core/dtypes/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from pandas._libs import Interval, Period, algos
1111
from pandas._libs.tslibs import conversion
12-
from pandas._typing import ArrayLike, DtypeObj
12+
from pandas._typing import ArrayLike, DtypeObj, Optional
1313

1414
from pandas.core.dtypes.base import registry
1515
from pandas.core.dtypes.dtypes import (
@@ -1732,7 +1732,7 @@ def _validate_date_like_dtype(dtype) -> None:
17321732
)
17331733

17341734

1735-
def validate_all_hashable(*args, error_name=None) -> None:
1735+
def validate_all_hashable(*args, error_name: Optional[str] = None) -> None:
17361736
"""
17371737
Return None if all args are hashable, else raise a TypeError.
17381738

pandas/tests/dtypes/test_common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,13 @@ def test_astype_object_preserves_datetime_na(from_type):
746746
result = astype_nansafe(arr, dtype="object")
747747

748748
assert isna(result)[0]
749+
750+
751+
def test_validate_allhashable():
752+
assert com.validate_all_hashable(1, "a") is None
753+
754+
with pytest.raises(TypeError, match="All elements must be hashable"):
755+
com.validate_all_hashable([])
756+
757+
with pytest.raises(TypeError, match="list must be a hashable type"):
758+
com.validate_all_hashable([], error_name="list")

0 commit comments

Comments
 (0)