Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 601612f

Browse files
committed
Fixed IndexError when split_text is True and table has empty rows or out of bound column text
1 parent d606d88 commit 601612f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

camelot/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ def split_textline(table, textline, direction, flag_size=False, strip_text=""):
592592
cut_text = []
593593
bbox = textline.bbox
594594
try:
595+
if textline.is_empty():
596+
return [(-1, -1, textline.get_text())]
597+
595598
if direction == "horizontal" and not textline.is_empty():
596599
x_overlap = [
597600
i
@@ -622,7 +625,8 @@ def split_textline(table, textline, direction, flag_size=False, strip_text=""):
622625
else:
623626
# TODO: add test
624627
if cut == x_cuts[-1]:
625-
cut_text.append((r, cut[0] + 1, obj))
628+
new_idx = min(cut[0] + 1, len(table.cols) - 1)
629+
cut_text.append((r, new_idx, obj))
626630
elif isinstance(obj, LTAnno):
627631
cut_text.append((r, cut[0], obj))
628632
elif direction == "vertical" and not textline.is_empty():
@@ -655,7 +659,8 @@ def split_textline(table, textline, direction, flag_size=False, strip_text=""):
655659
else:
656660
# TODO: add test
657661
if cut == y_cuts[-1]:
658-
cut_text.append((cut[0] - 1, c, obj))
662+
new_idx = max(cut[0] - 1, 0)
663+
cut_text.append((new_idx, c, obj))
659664
elif isinstance(obj, LTAnno):
660665
cut_text.append((cut[0], c, obj))
661666
except IndexError:

0 commit comments

Comments
 (0)