# Buggy code
def get_candidates_and_features_page_num(self, page_num):
    elems = self.elems[page_num]
    #  font_stat = self.font_stats[page_num]
    #  lines_bboxes = self.get_candidates_lines(page_num, elems)
    alignments_bboxes, alignment_features = self.get_candidates_alignments(
        page_num, elems
    )
    # print "Page Num: ", page_num, "Line bboxes: ", len(lines_bboxes), ", Alignment bboxes: ", len(alignments_bboxes)
    # alignment_features += get_alignment_features(lines_bboxes, elems, font_stat)
    boxes = alignments_bboxes  # + lines_bboxes
    if len(boxes) == 0:
        return [], []
    lines_features = get_lines_features(boxes, elems)
    features = np.concatenate(
        (np.array(alignment_features), np.array(lines_features)), axis=1
    )
    return boxes, features


# Traceback (IndexError)
$ pdftotree -vv dtc114w.pdf
[INFO] pdftotree.core - Digitized PDF detected, building tree structure...
[ERROR] pdftotree.TreeExtract - list index out of range
Traceback (most recent call last):
File "/home/lwhsiao/repos/pdftotree/pdftotree/TreeExtract.py", line 148, in get_candidates_alignments
nodes, features = parse_layout(elems, font_stat)
File "/home/lwhsiao/repos/pdftotree/pdftotree/utils/pdf/pdf_parsers.py", line 36, in parse_layout
avg_font_pts = get_most_common_font_pts(elems.mentions, font_stat)
File "/home/lwhsiao/repos/pdftotree/pdftotree/utils/pdf/pdf_parsers.py", line 1159, in get_most_common_font_pts
most_common_font_size = font_stat.most_common(1)[0][0]
IndexError: list index out of range
Traceback (most recent call last):
File "/home/lwhsiao/repos/pdftotree/.venv/bin/pdftotree", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/home/lwhsiao/repos/pdftotree/bin/pdftotree", line 82, in <module>
args.favor_figures, args.visualize)
File "/home/lwhsiao/repos/pdftotree/pdftotree/core.py", line 58, in parse
pdf_tree = extractor.get_tree_structure(model, favor_figures)
File "/home/lwhsiao/repos/pdftotree/pdftotree/TreeExtract.py", line 188, in get_tree_structure
favor_figures)
File "/home/lwhsiao/repos/pdftotree/pdftotree/utils/pdf/pdf_parsers.py", line 666, in parse_tree_structure
avg_font_pts = get_most_common_font_pts(elems.mentions, font_stat)
File "/home/lwhsiao/repos/pdftotree/pdftotree/utils/pdf/pdf_parsers.py", line 1159, in get_most_common_font_pts
most_common_font_size = font_stat.most_common(1)[0][0]
IndexError: list index out of range

# Fixed code
def get_candidates_and_features_page_num(self, page_num):
    elems = self.elems[page_num]
    #  font_stat = self.font_stats[page_num]
    #  lines_bboxes = self.get_candidates_lines(page_num, elems)
    alignments_bboxes, alignment_features = self.get_candidates_alignments(
        page_num, elems
    )
    # print "Page Num: ", page_num, "Line bboxes: ", len(lines_bboxes), ", Alignment bboxes: ", len(alignments_bboxes)
    # alignment_features += get_alignment_features(lines_bboxes, elems, font_stat)
    boxes = alignments_bboxes  # + lines_bboxes
    if len(boxes) == 0:
        log.info("No boxes were found on page {}.".format(page_num))
        return [], []
    lines_features = get_lines_features(boxes, elems)
    features = np.concatenate(
        (np.array(alignment_features), np.array(lines_features)), axis=1
    )
    return boxes, features