Skip to content

dtype does not get set to object when adding column with df.at[...] = ['some list'] #30649

Open
@McToel

Description

@McToel

Code Sample, a copy-pastable example if possible

df = pd.DataFrame(data={'a':[0,0]})
# df['b'] = None
# df['b'] = df['b'].astype('object')
df.at[0, 'b'] = ['a']
df.at[1, 'b'] = ['a']

>>> df
   a    b
0  0    a
1  0  [a]

Problem description

df.at[0, 'b'] should be ['a'] instead of 'a'.
I understand that it does not work when while adding the column but it feels inconsistent anyways.
When adding line 2 and 3 it works as expected.

Expected Output

>>> df
   a    b
0  0  [a]
1  0  [a]

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 0.25.3
numpy : 1.18.0
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 41.2.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.10.2
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

Metadata

Metadata

Assignees

Labels

IndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions