Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ Bug Fixes
- Bug in ``Float64Index`` where ``iat`` and ``at`` were not testing and were
failing (:issue:`8092`).


- Bug in ``read_html`` where empty tables caused a ``StopIteration`` (:issue:`7575`)



Expand Down
11 changes: 8 additions & 3 deletions pandas/io/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,9 +711,14 @@ def _parse(flavor, io, match, header, index_col, skiprows, infer_types,
else:
raise_with_traceback(retained)

return [_data_to_frame(table, header, index_col, skiprows, infer_types,
parse_dates, tupleize_cols, thousands)
for table in tables]
ret = []
for table in tables:
try:
ret.append(_data_to_frame(table, header, index_col, skiprows,
infer_types, parse_dates, tupleize_cols, thousands))
except StopIteration: # empty table
continue
return ret


def read_html(io, match='.+', flavor=None, header=None, index_col=None,
Expand Down
26 changes: 26 additions & 0 deletions pandas/io/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,32 @@ def test_thousands_macau_index_col(self):

self.assertFalse(any(s.isnull().any() for _, s in df.iteritems()))

def test_empty_tables(self):
"""
Make sure that read_html ignores empty tables.
"""
data1 = '''<table>
<thead>
<tr>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
</tr>
</tbody>
</table>'''
data2 = data1 + '''<table>
<tbody>
</tbody>
</table>'''
res1 = self.read_html(StringIO(data1))
res2 = self.read_html(StringIO(data2))
assert_framelist_equal(res1, res2)

def test_countries_municipalities(self):
# GH5048
data1 = StringIO('''<table>
Expand Down