pandas.api.types.is_hashable#

pandas.api.types.is_hashable(obj)[source]#

Return True if hash(obj) will succeed, False otherwise.

Some types will pass a test against collections.abc.Hashable but fail when they are actually hashed with hash().

Distinguish between these and other types by trying the call to hash() and seeing if they raise TypeError.

Parameters:
objobject

The object to check for hashability. Any Python object can be passed here.

Returns:
bool

True if object can be hashed (i.e., does not raise TypeError when passed to hash()), and False otherwise (e.g., if object is mutable like a list or dictionary).

See also

api.types.is_float

Return True if given object is float.

api.types.is_iterator

Check if the object is an iterator.

api.types.is_list_like

Check if the object is list-like.

api.types.is_dict_like

Check if the object is dict-like.

Examples

>>> import collections
>>> from pandas.api.types import is_hashable
>>> a = ([],)
>>> isinstance(a, collections.abc.Hashable)
True
>>> is_hashable(a)
False