Skip to content

CLN: refactor hash_array to resolve circular dependency #53347

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 6 commits into from
May 24, 2023
Merged
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
11 changes: 6 additions & 5 deletions pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def hash_array(
encoding=encoding, hash_key=hash_key, categorize=categorize
)

elif not isinstance(vals, np.ndarray):
if not isinstance(vals, np.ndarray):
# GH#42003
raise TypeError(
"hash_array requires np.ndarray or ExtensionArray, not "
Expand All @@ -275,14 +275,15 @@ def _hash_ndarray(
"""
dtype = vals.dtype

# we'll be working with everything as 64-bit values, so handle this
# 128-bit value early
# _hash_ndarray only takes 64-bit values, so handle 128-bit by parts
if np.issubdtype(dtype, np.complex128):
return hash_array(np.real(vals)) + 23 * hash_array(np.imag(vals))
hash_real = _hash_ndarray(vals.real, encoding, hash_key, categorize)
hash_imag = _hash_ndarray(vals.imag, encoding, hash_key, categorize)
return hash_real + 23 * hash_imag

# First, turn whatever array this is into unsigned 64-bit ints, if we can
# manage it.
elif dtype == bool:
if dtype == bool:
vals = vals.astype("u8")
elif issubclass(dtype.type, (np.datetime64, np.timedelta64)):
vals = vals.view("i8").astype("u8", copy=False)
Expand Down