projektAI/venv/Lib/site-packages/pandas/tests/dtypes/cast/test_construct_from_scalar.py
2021-06-06 22:13:05 +02:00

19 lines
650 B
Python

from pandas.core.dtypes.cast import construct_1d_arraylike_from_scalar
from pandas.core.dtypes.dtypes import CategoricalDtype
from pandas import Categorical
import pandas._testing as tm
def test_cast_1d_array_like_from_scalar_categorical():
# see gh-19565
#
# Categorical result from scalar did not maintain
# categories and ordering of the passed dtype.
cats = ["a", "b", "c"]
cat_type = CategoricalDtype(categories=cats, ordered=False)
expected = Categorical(["a", "a"], categories=cats)
result = construct_1d_arraylike_from_scalar("a", len(expected), cat_type)
tm.assert_categorical_equal(result, expected)