BUG: astype(CategoricalDtype) has no effect · Issue #15078 · pandas-dev/pandas (original) (raw)
The following fails silently to convert the dtype:
In [14]: s = pd.Series(['a', 'b', 'c'])
In [15]: s
Out[15]:
0 a
1 b
2 c
dtype: object
In [16]: s.astype(pd.types.dtypes.CategoricalDtype)
Out[16]:
0 a
1 b
2 c
I would think this either to work or either to raise an error that the dtype is not undertood.
Code Sample
When using dictionnary of dtype, it does not convert the dataframe :
Types are not modified whereas df['col']= df['col].astype(type1) works....
dtype0= {'brand': np.dtype('int64'),
'category': np.dtype('int64'),
'chain': np.dtype('int64'),
'company': np.dtype('int64'),
'date': np.dtype('O'),
'dept': pandas.types.dtypes.CategoricalDtype,
'id': np.dtype('int64')}
df= df.astype(dtype0)
df.dtypes
Problem description
When using dictionnary of dtype, it does not convert the dataframe :
Types are not modified whereas df['col']= df['col].astype(type1) works....
Expected Output
columns are converted into the desire types.
Output of pd.show_versions()
Pandas 0.19.2
# Paste the output here pd.show_versions() here