Skip to content

Commit 03d8cd2

Browse files
author
Khor Chean Wei
authored
Test: IntervalIndex.astype("category") doesn't preserve exact interval dtype in categories (#48226)
* add test * add test * add test * revert * revert * add test * add test * add test * revert * revert * add test * Update test_dtypes.py
1 parent 9757d1f commit 03d8cd2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/tests/arrays/categorical/test_dtypes.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import pytest
23

34
from pandas.core.dtypes.dtypes import CategoricalDtype
@@ -6,6 +7,7 @@
67
Categorical,
78
CategoricalIndex,
89
Index,
10+
IntervalIndex,
911
Series,
1012
Timestamp,
1113
)
@@ -134,3 +136,13 @@ def test_iter_python_types_datetime(self):
134136
cat = Categorical([Timestamp("2017-01-01"), Timestamp("2017-01-02")])
135137
assert isinstance(list(cat)[0], Timestamp)
136138
assert isinstance(cat.tolist()[0], Timestamp)
139+
140+
def test_interval_index_category(self):
141+
# GH 38316
142+
index = IntervalIndex.from_breaks(np.arange(3, dtype="uint64"))
143+
144+
result = CategoricalIndex(index).dtype.categories
145+
expected = IntervalIndex.from_arrays(
146+
[0, 1], [1, 2], dtype="interval[uint64, right]"
147+
)
148+
tm.assert_index_equal(result, expected)

0 commit comments

Comments
 (0)