Skip to content

A future error warning and a problem with autoconversion of types  #22252

Closed
@dbfin

Description

@dbfin

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).

   a    b
0  1  2.0
0  3  NaN

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIndexingRelated to indexing on series/frames, not to indexes themselvesReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions