Skip to content

Commit 7840030

Browse files
committed
add explicit test
1 parent 359befa commit 7840030

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/indexes/ranges/test_range.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pandas as pd
77
from pandas import (
8+
CategoricalDtype,
9+
CategoricalIndex,
810
Float64Index,
911
Index,
1012
Int64Index,
@@ -533,3 +535,28 @@ def test_isin_range(self, base):
533535
result = base.isin(values)
534536
expected = np.array([True, False])
535537
tm.assert_numpy_array_equal(result, expected)
538+
539+
@pytest.mark.parametrize("copy", [True, False])
540+
@pytest.mark.parametrize("name", [None, "foo"])
541+
@pytest.mark.parametrize("ordered", [True, False])
542+
def test_astype_category(self, copy, name, ordered, simple_index):
543+
super().test_astype_category(copy, name, ordered, simple_index)
544+
545+
# GH 41263
546+
idx = simple_index
547+
if name:
548+
idx = idx.rename(name)
549+
550+
# standard categories
551+
dtype = CategoricalDtype(ordered=ordered)
552+
result = idx.astype(dtype, copy=copy)
553+
assert isinstance(result, CategoricalIndex)
554+
assert isinstance(result.categories, RangeIndex)
555+
assert (result.categories == idx).all()
556+
557+
if ordered is False:
558+
# dtype='category' defaults to ordered=False, so only test once
559+
result = idx.astype("category", copy=copy)
560+
assert isinstance(result, CategoricalIndex)
561+
assert isinstance(result.categories, RangeIndex)
562+
assert (result.categories == idx).all()

0 commit comments

Comments
 (0)