xref https://github.com/pydata/pandas/issues/8596
>>> df
a
0 1
>>> df.dtypes
a int64
dtype: object
>>> df.loc[1, 'a'] = 2
>>> df
a
0 1
1 2
>>> df.dtypes
a float64
dtype: object
in an intermediate step nan
is inserted, and the data are casted to floats
Comment From: jreback
type conversion is not done here. as it can be expensive. imagine doing this repeatedly (not recommended anyhow).
This is a side-effect of this type of enlargement. a user can use concat
if they want type preservation. However, you can fix the impl to avoid the 2-step creation with missing then filling.
Is that the intention here? as an enhnacement?
Comment From: behzadnouri
agreed that a code change to handle this should not be expensive in terms of performance cost; added the issue just because https://github.com/pydata/pandas/issues/8596 is a similar issue, so there may be a solution which works for both cases.
Comment From: goretkin
can concat
guarantee that the new row is added in-place?
Comment From: shoyer
can concat guarantee that the new row is added in-place?
concat never updates in-place.
Comment From: jorisvandenbossche
This actually seems a duplicate of https://github.com/pydata/pandas/issues/6485 (BUG/ENH: dtype change on enlargement).