Skip to content

BUG: hashing read only object categories raises #58481

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 2 commits into from
Apr 30, 2024
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
3 changes: 2 additions & 1 deletion pandas/_libs/hashing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import numpy as np

from numpy cimport (
import_array,
ndarray,
uint8_t,
uint64_t,
)
Expand All @@ -22,7 +23,7 @@ from pandas._libs.util cimport is_nan

@cython.boundscheck(False)
def hash_object_array(
object[:] arr, str key, str encoding="utf8"
ndarray[object, ndim=1] arr, str key, str encoding="utf8"
) -> np.ndarray[np.uint64]:
"""
Parameters
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/arrays/categorical/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,11 @@ def test_diff():
df = ser.to_frame(name="A")
with pytest.raises(TypeError, match=msg):
df.diff()


def test_hash_read_only_categorical():
# GH#58481
idx = pd.Index(pd.Index(["a", "b", "c"], dtype="object").values)
cat = pd.CategoricalDtype(idx)
arr = pd.Series(["a", "b"], dtype=cat).values
assert hash(arr.dtype) == hash(arr.dtype)