diff --git a/doc/source/v0.15.0.txt b/doc/source/v0.15.0.txt index 95bf2918f8992..355e90291b0e3 100644 --- a/doc/source/v0.15.0.txt +++ b/doc/source/v0.15.0.txt @@ -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`) diff --git a/pandas/io/html.py b/pandas/io/html.py index 44dcfb6117d72..402758815e95b 100644 --- a/pandas/io/html.py +++ b/pandas/io/html.py @@ -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, diff --git a/pandas/io/tests/test_html.py b/pandas/io/tests/test_html.py index 834140e3de746..748a008ae2c4b 100644 --- a/pandas/io/tests/test_html.py +++ b/pandas/io/tests/test_html.py @@ -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 = '''
A | +B | +
---|---|
1 | +2 | +