Skip to content

read_csv index_col ignores dtype if specified #12999

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
alzmcr opened this issue Apr 26, 2016 · 1 comment
Closed

read_csv index_col ignores dtype if specified #12999

alzmcr opened this issue Apr 26, 2016 · 1 comment
Labels
Bug Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv

Comments

@alzmcr
Copy link

alzmcr commented Apr 26, 2016

Hi, I'm not sure if this is intended but when using the index_col parameter in read_csv it ignore the input format specified in dtype. It's reproducible as following using pandas 0.18.0 and numpy 1.11.0.

>>> from StringIO import StringIO
import pandas as pd
df_csv = """request_hour,request_date,size
03,2016-04-26,2580954.0
04,2016-04-26,12003662.0
05,2016-04-26,13042624.0
06,2016-04-26,2899309.0
07,2016-04-26,-1.0"""

>>> pd.read_csv(StringIO(df_csv), dtype={'request_hour': 'string'}).set_index('request_hour')

             request_date        size
request_hour                         
03             2016-04-26   2580954.0
04             2016-04-26  12003662.0
05             2016-04-26  13042624.0
06             2016-04-26   2899309.0
07             2016-04-26        -1.0
# This is what I would expected as output

>>> pd.read_csv(StringIO(df_csv), dtype={'request_hour': 'string'}, index_col=0)

             request_date        size
request_hour                         
3              2016-04-26   2580954.0
4              2016-04-26  12003662.0
5              2016-04-26  13042624.0
6              2016-04-26   2899309.0
7              2016-04-26        -1.0
# I'm surprise that the index has been converted to int

I couldn't find any specs on this anywhere, so I wonder if something with the read_csv or I'm doing something wrong.

Thanks!

@jreback jreback added Bug Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv labels Apr 26, 2016
@jreback jreback added this to the No action milestone Apr 26, 2016
@jreback
Copy link
Contributor

jreback commented Apr 26, 2016

dupe of #9435

@jreback jreback closed this as completed Apr 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv
Projects
None yet
Development

No branches or pull requests

2 participants