Skip to content

Commit

Permalink
BUG: hashing read only object categories raises (#58481)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Apr 30, 2024
1 parent 086b047 commit 59f6a33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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)

0 comments on commit 59f6a33

Please sign in to comment.