A future error warning and a problem with autoconversion of types · Issue #22252 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import pandas as pd pd.DataFrame([ { 'a': 1, 'b': 2 } ]).append([ { 'a': 3 } ])
Problem description
Problem 1. The result is as expected (except for 2.0
instead of 2
, see Problem 2).
However, Python gives a warning
/usr/lib/python3.7/site-packages/pandas/core/indexing.py:1472: FutureWarning:
Passing list-likes to .loc or [] with any missing label will raise
KeyError in the future, you can use .reindex() as an alternative.
The warning suggests that this will be an exception in the future. The code seems legitimate, and as such produces the expected result.
Problem 2. Another problem can be illustrated by this output:
pd.DataFrame([ { 'a': 1, 'b': 2 } ]).dtypes
a int64
b int64
dtype: object
pd.DataFrame([ { 'a': 1, 'b': 2 } ]).append([ { 'a': 3 } ]).dtypes
a int64
b float64
dtype: object
Why the type of b
is changed to Float64?
Expected Output
a b
0 1 2
0 3 NaN
a int64
b int64
dtype: object
a int64
b int64
dtype: object
Output of pd.show_versions()
python: 3.7.0.final.0
python-bits: 64
pandas: 0.23.1