Skip to content

Commit bb399a1

Browse files
phoflpmhatre1
authored andcommitted
BUG: hashing read only object categories raises (pandas-dev#58481)
1 parent bee9d7a commit bb399a1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/_libs/hashing.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import numpy as np
1111

1212
from numpy cimport (
1313
import_array,
14+
ndarray,
1415
uint8_t,
1516
uint64_t,
1617
)
@@ -22,7 +23,7 @@ from pandas._libs.util cimport is_nan
2223

2324
@cython.boundscheck(False)
2425
def hash_object_array(
25-
object[:] arr, str key, str encoding="utf8"
26+
ndarray[object, ndim=1] arr, str key, str encoding="utf8"
2627
) -> np.ndarray[np.uint64]:
2728
"""
2829
Parameters

pandas/tests/arrays/categorical/test_algos.py

+8
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ def test_diff():
8686
df = ser.to_frame(name="A")
8787
with pytest.raises(TypeError, match=msg):
8888
df.diff()
89+
90+
91+
def test_hash_read_only_categorical():
92+
# GH#58481
93+
idx = pd.Index(pd.Index(["a", "b", "c"], dtype="object").values)
94+
cat = pd.CategoricalDtype(idx)
95+
arr = pd.Series(["a", "b"], dtype=cat).values
96+
assert hash(arr.dtype) == hash(arr.dtype)

0 commit comments

Comments
 (0)