Unexpected dtype when using .loc to set Categorical value for column in 1-row DataFrame #25495
Labels
Bug
Categorical
Categorical Data Type
Indexing
Related to indexing on series/frames, not to indexes themselves
Milestone
Code Sample, a copy-pastable example if possible
Problem description
When I try to set the column of a one-row DataFrame to a
pandas.core.arrays.categorical.Categorical
, it is returned as apandas.core.series.Series
ofdtype('O')
rather than apandas.core.series.Series
ofCategoricalDtype(categories=[u'a', u'b', u'c'], ordered=False)
. I get the latter return value when I set the column usingdf['Alpha'] = codes
ordf.Alpha = codes
. I can't replicate this inconsistency with DataFrames containing more than one row.Expected Output
Output of
pd.show_versions()
[paste the output of
pd.show_versions()
here below this line]INSTALLED VERSIONS
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Darwin
OS-release: 18.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.24.1
pytest: None
pip: 19.0.3
setuptools: 40.6.3
Cython: None
numpy: 1.15.4
scipy: 1.2.0
pyarrow: None
xarray: None
IPython: 5.8.0
sphinx: None
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: