Skip to content

Commit

Permalink
Add check for None bounding boxes for AnalyzeExpense
Browse files Browse the repository at this point in the history
  • Loading branch information
Belval authored Nov 6, 2024
2 parents c4e2f7b + bc95117 commit 70d8683
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion textractor/entities/expense_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ def bbox(self):
# Dangerous, we need at least one expense in an expense row
return BoundingBox.enclosing_bbox(
[f.bbox for f in self._line_item_expense_fields],
spatial_object=self.expenses[0].bbox.spatial_object,
spatial_object=[
ex
for ex in self.expenses
if ex.bbox
][0].bbox.spatial_object,
)

def __getitem__(self, index):
Expand Down
6 changes: 6 additions & 0 deletions textractor/visualizers/entitylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ def _draw_bbox(

# First drawing tables
for entity in entities:
if entity.bbox is None:
continue
width, height = image.size
if entity.__class__.__name__ == "Table":
overlayer_data = _get_overlayer_data(entity, width, height)
Expand Down Expand Up @@ -751,6 +753,8 @@ def _draw_bbox(
)
# Second drawing bounding boxes
for entity in entities:
if entity.bbox is None:
continue
if entity.__class__.__name__ == "Query":
overlayer_data = _get_overlayer_data(entity.result, width, height)
drw.rectangle(
Expand Down Expand Up @@ -836,6 +840,8 @@ def _draw_bbox(
# Second drawing, text
if with_text:
for entity in entities:
if entity.bbox is None:
continue
if entity.__class__.__name__ == "Word":
width, height = image.size
overlayer_data = _get_overlayer_data(entity, width, height)
Expand Down

0 comments on commit 70d8683

Please sign in to comment.