Skip to content

Test: IntervalIndex.astype("category") doesn't preserve exact interval dtype in categories #48226

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 18 commits into from
Aug 29, 2022
12 changes: 12 additions & 0 deletions pandas/tests/arrays/categorical/test_dtypes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import pytest

from pandas.core.dtypes.dtypes import CategoricalDtype
Expand All @@ -6,6 +7,7 @@
Categorical,
CategoricalIndex,
Index,
IntervalIndex,
Series,
Timestamp,
)
Expand Down Expand Up @@ -134,3 +136,13 @@ def test_iter_python_types_datetime(self):
cat = Categorical([Timestamp("2017-01-01"), Timestamp("2017-01-02")])
assert isinstance(list(cat)[0], Timestamp)
assert isinstance(cat.tolist()[0], Timestamp)

def test_interval_index_category(self):
# GH 38316
index = IntervalIndex.from_breaks(np.arange(3, dtype="uint64"))

result = CategoricalIndex(index).dtype.categories
expected = IntervalIndex.from_arrays(
[0, 1], [1, 2], dtype="interval[uint64, right]"
)
tm.assert_index_equal(result, expected)