Closed
Description
In [1]: import pandas as pd
In [2]: a = pd.Series(['a', 'b', 'c'])
In [3]: dtype = pd.api.types.CategoricalDtype(['x', 'y', 'z'])
In [4]: b = a.astype('category')
In [5]: b
Out[5]:
0 a
1 b
2 c
dtype: category
Categories (3, object): [a, b, c]
In [6]: b.astype(dtype)
Out[6]:
0 a
1 b
2 c
dtype: category
Categories (3, object): [a, b, c]
In [7]: pd.__version__
Out[7]: '0.21.0'
I'd expect b.astype(dtype)
to re-categorize b
with the new categories from the categorical dtype. Instead, it seems this operation is ignored.