You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
776 B
Python
29 lines
776 B
Python
import pytest
|
|
|
|
from pandas import (
|
|
Categorical,
|
|
CategoricalDtype,
|
|
Index,
|
|
IntervalIndex,
|
|
)
|
|
import pandas._testing as tm
|
|
|
|
|
|
class TestAstype:
|
|
@pytest.mark.parametrize("ordered", [True, False])
|
|
def test_astype_categorical_retains_ordered(self, ordered):
|
|
index = IntervalIndex.from_breaks(range(5))
|
|
arr = index._data
|
|
|
|
dtype = CategoricalDtype(None, ordered=ordered)
|
|
|
|
expected = Categorical(list(arr), ordered=ordered)
|
|
result = arr.astype(dtype)
|
|
assert result.ordered is ordered
|
|
tm.assert_categorical_equal(result, expected)
|
|
|
|
# test IntervalIndex.astype while we're at it.
|
|
result = index.astype(dtype)
|
|
expected = Index(expected)
|
|
tm.assert_index_equal(result, expected)
|