read_csv ignores dtype for empty CSV files #14712

Closed
jluttine opened this Issue Nov 22, 2016 · 0 comments

Comments

Projects
None yet
3 participants

Code Sample, a copy-pastable example if possible

>>> import io
>>> import pandas as pd
>>> pd.read_csv(io.StringIO('foo,bar'), header=0, dtype=np.float64).values
array([], shape=(0, 2), dtype=object)

Problem description

CSV reader doesn't respect the given dtype np.float64 but sets object dtype instead.

Expected Output

array([], shape=(0, 2), dtype=float64)

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 4.8.8-gnu-1 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.19.1
nose: 1.3.7
pip: 8.1.2
setuptools: 28.8.0
Cython: 0.25.1
numpy: 1.11.2
scipy: 0.18.1
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: 1.4.8
patsy: None
dateutil: 2.6.0
pytz: 2016.7
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.5.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.5.5
sqlalchemy: 1.1.4
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None

gfyoung referenced this issue Nov 22, 2016

Merged

API: add dtype= option to python parser #14295

4 of 4 tasks complete

@gfyoung gfyoung added a commit to gfyoung/pandas that referenced this issue Nov 22, 2016

@gfyoung gfyoung BUG: Respect the dtype parameter for empty CSV
Closes gh-14712.
30ac610

jreback added this to the Next Major Release milestone Nov 22, 2016

@gfyoung gfyoung added a commit to gfyoung/pandas that referenced this issue Nov 23, 2016

@gfyoung gfyoung BUG: Respect the dtype parameter for empty CSV
Closes gh-14712.
f87a976

@gfyoung gfyoung added a commit to gfyoung/pandas that referenced this issue Nov 23, 2016

@gfyoung gfyoung BUG: Respect the dtype parameter for empty CSV
Closes gh-14712.
cee4d6a

@jreback jreback modified the milestone: 0.20.0, Next Major Release Nov 23, 2016

@jorisvandenbossche jorisvandenbossche modified the milestone: 0.19.2, 0.20.0 Nov 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment