read_excel crash with empty Exception #12292

Closed
bteplygin opened this Issue Feb 11, 2016 · 3 comments

Comments

Projects
None yet
2 participants

If read one empty column from excel file, read_excel raise Exception without error message.
Small test case: content of excel file:

A B C D
1 100 f
2 200 f
3 300 f
4 400 f

Run:

import pandas as pd
pd.read_excel("test_excel_.xls", parse_cols=[0], header=None)

Result:

File "/home/.../python2.7/site-packages/pandas/io/excel.py", line 170, in read_excelskip_footer=skip_footer, converters=converters, **kwds)
File "/home/.../python2.7/site-packages/pandas/io/excel.py", line 436, in _parse_excel**kwds)
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 1346, in TextParserreturn TextFileReader(*args, **kwds)
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 590, in __init__self._make_engine(self.engine)
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 737, in _make_engineself._engine = klass(self.f, **self.options)
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 1452, in __init__self.columns, self.num_original_columns = self._infer_columns()
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 1735, in _infer_columnsline = self._buffered_line()
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 1793, in _buffered_linereturn self._next_line()
File "/home/.../python2.7/site-packages/pandas/io/parsers.py", line 1817, in _next_lineraise StopIteration

Python 2.7.7
pandas 0.17.1
xlrd 0.9.4

Contributor

jreback commented Feb 11, 2016

can you programatically create this example as a frame and write it to excel, alternatively post a link to the actual excel file (first is preferred if you can replicate the actual error)

For example:

import pandas as pd
df = pd.DataFrame([["", 1, 100], ["", 2, 200], ["", 3, 300], ["", 4, 400]])
df.to_excel("test_excel.xls", index=False, header=False)
pd.read_excel("test_excel.xls", parse_cols=[0], header=None)
Contributor

jreback commented Feb 11, 2016

@bteblygin thanks!

PR to fix would be great!

jreback added this to the Next Major Release milestone Feb 11, 2016

@BranYang BranYang added a commit to BranYang/pandas that referenced this issue Feb 17, 2016

@BranYang BranYang Fix #12292 : error when read one empty column from excel file
This time I didn't touch the parser, just inside the excel.py itself.
0032460

@jreback jreback modified the milestone: 0.18.0, Next Major Release Feb 23, 2016

jreback closed this in 78d671f Feb 27, 2016

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