Skip to content

Commit

Permalink
Prevent taking the max of an empty set
Browse files Browse the repository at this point in the history
  • Loading branch information
pevisscher committed Aug 25, 2020
1 parent aae2c6b commit 3e7189d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions camelot/parsers/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _generate_columns_and_rows(self, table_idx, tk):
rows_grouped = self._group_rows(self.t_bbox["horizontal"], row_tol=self.row_tol)
rows = self._join_rows(rows_grouped, text_y_max, text_y_min)
elements = [len(r) for r in rows_grouped]

cols = []
if self.columns is not None and self.columns[table_idx] != "":
# user has to input boundary columns too
# take (0, pdf_width) by default
Expand All @@ -342,7 +342,7 @@ def _generate_columns_and_rows(self, table_idx, tk):
cols.insert(0, text_x_min)
cols.append(text_x_max)
cols = [(cols[i], cols[i + 1]) for i in range(0, len(cols) - 1)]
else:
elif elements:
# calculate mode of the list of number of elements in
# each row to guess the number of columns
ncols = max(set(elements), key=elements.count)
Expand Down Expand Up @@ -455,8 +455,9 @@ def extract_tables(self, filename, suppress_stdout=False, layout_kwargs={}):
sorted(self.table_bbox.keys(), key=lambda x: x[1], reverse=True)
):
cols, rows = self._generate_columns_and_rows(table_idx, tk)
table = self._generate_table(table_idx, cols, rows)
table._bbox = tk
_tables.append(table)
if cols and rows:
table = self._generate_table(table_idx, cols, rows)
table._bbox = tk
_tables.append(table)

return _tables

0 comments on commit 3e7189d

Please sign in to comment.