Skip to content

REGR: Fixed hash_key=None for object values #30900

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

Merged
merged 3 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
data hash pandas / numpy objects
"""
import itertools
from typing import Optional

import numpy as np

Expand Down Expand Up @@ -58,7 +59,7 @@ def hash_pandas_object(
obj,
index: bool = True,
encoding: str = "utf8",
hash_key: str = _default_hash_key,
hash_key: Optional[str] = _default_hash_key,
categorize: bool = True,
):
"""
Expand All @@ -82,6 +83,9 @@ def hash_pandas_object(
"""
from pandas import Series

if hash_key is None:
hash_key = _default_hash_key

if isinstance(obj, ABCMultiIndex):
return Series(hash_tuples(obj, encoding, hash_key), dtype="uint64", copy=False)

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/util/test_hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,10 @@ def test_hash_with_tuple():
df3 = pd.DataFrame({"data": [tuple([1, []]), tuple([2, {}])]})
with pytest.raises(TypeError, match="unhashable type: 'list'"):
hash_pandas_object(df3)


def test_hash_object_none_key():
# https://github.com/pandas-dev/pandas/issues/30887
result = pd.util.hash_pandas_object(pd.Series(["a", "b"]), hash_key=None)
expected = pd.Series([4578374827886788867, 17338122309987883691], dtype="uint64")
tm.assert_series_equal(result, expected)