Skip to content

Integers converted to floats when round-tripping through Excel #4932

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
jtratner opened this issue Sep 22, 2013 · 4 comments
Closed

Integers converted to floats when round-tripping through Excel #4932

jtratner opened this issue Sep 22, 2013 · 4 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Enhancement IO Excel read_excel, to_excel
Milestone

Comments

@jtratner
Copy link
Contributor

0.12 and current master have this problem (problem is that we were only testing frames with floats):

>>> df = DataFrame(range(10))
>>> df.dtypes
0    int64
dtype: object
>>> df.index
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)
>>> df.to_excel('test1.xlsx')
>>> new_df = read_excel('test1.xlsx', 'sheet1')
>>> new_df.index
Index([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype=object)
>>> new_df.dtypes
0    float64
dtype: object

Can we do some type inference here or something? read_csv handles it better:

>>> df.to_csv('out.csv')
>>> new_df = read_csv('out.csv')
>>> new_df.index
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int64)
>>> new_df.dtypes
Unnamed: 0    int64
0             int64
dtype: object
@ghost ghost assigned jtratner Sep 22, 2013
@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

try this: df._data.downcast(dtype='infer')

@jtratner
Copy link
Contributor Author

@jreback so could we add a keyword argument infer and default it to True so it roundtrips without issue? How do other parts of the library handle it?

@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

you have float to int inference and int/float say to timedelta (but leave this for later)

downcast will do these 4 u (timedelta is a bit trickier)

@jreback
Copy link
Contributor

jreback commented Mar 3, 2015

need an update on this issue.

@jreback jreback closed this as completed Mar 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Enhancement IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

2 participants