Skip to content

Commit 4309e9e

Browse files
authored
fix: list index out of range error caused by calling LayoutElements.from_list() with empty list (#398)
error coming from https://github.com/Unstructured-IO/core-product/actions/runs/11510770484/job/32043653203?pr=662#step:5:718 or lmk if there are better way to fix error w/o changing here :)
1 parent 7b43309 commit 4309e9e

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.8.1
2+
* fix: fix list index out of range error caused by calling LayoutElements.from_list() with empty list
3+
14
## 0.8.0
25

36
* fix: fix missing source after cleaning layout elements

test_unstructured_inference/test_elements.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,8 @@ def test_layoutelements_to_list_and_back(test_layoutelements):
436436
test_layoutelements.element_class_id_map[idx]
437437
for idx in test_layoutelements.element_class_ids
438438
] == [back.element_class_id_map[idx] for idx in back.element_class_ids]
439+
440+
441+
def test_layoutelements_from_list_no_elements():
442+
back = LayoutElements.from_list(elements=[])
443+
assert back.source is None
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.0" # pragma: no cover
1+
__version__ = "0.8.1" # pragma: no cover

unstructured_inference/inference/layoutelement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def from_list(cls, elements: list):
145145
element_probs=np.array(class_probs),
146146
element_class_ids=class_ids,
147147
element_class_id_map=dict(zip(range(len(unique_ids)), unique_ids)),
148-
source=elements[0].source,
148+
source=elements[0].source if len_ele else None,
149149
)
150150

151151

0 commit comments

Comments
 (0)