Skip to content

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

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

Closed
dbfin opened this issue Aug 8, 2018 · 2 comments · Fixed by #26022
Closed

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

dbfin opened this issue Aug 8, 2018 · 2 comments · Fixed by #26022
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@dbfin
Copy link

dbfin 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
Copy link
Contributor

jreback 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

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode Difficulty Intermediate labels Aug 9, 2018
@jreback jreback added this to the Contributions Welcome milestone Aug 9, 2018
@dbfin
Copy link
Author

dbfin 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
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants