Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dbfin opened this issue Aug 8, 2018 · 2 comments

Comments

@dbfin
Copy link

commented Aug 8, 2018

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
@jreback

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2018

  1. seems like a bug, if you'd like to have a look
  2. is as expected, see: http://pandas.pydata.org/pandas-docs/stable/gotchas.html#nan-integer-na-values-and-na-type-promotions
@dbfin

This comment has been minimized.

Copy link
Author

commented Aug 10, 2018

Problem 2. Thanks a lot for the link, very useful information (and not just regarding the mentioned problem). Actually, never noticed the problem before, until needed to write to a database recently and this changed the type of a column in the database after adding some missing values. So, this is not an issue anymore as this is by design.

Problem 1. I am not sure I can do this now. If you assign it to me, I'll remember to look into it later. This is if you have no immediate plans to look into this yourself or assign someone else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.