Unstructured-IO / Unstructured-IO/unstructured-inference

bug/error on HTML table generation

Open
#369 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
209
Forks
73
PR merge metrics
No merged PRs in 30d

Description

When processing a PDF file with hi_res in unstructured-api, an error occurs on HTML table generation (from unstructured-inferece):

2024-07-24T08:49:18.887448624Z   File "/home/notebook-user/.local/lib/python3.11/site-packages/unstructured/partition/pdf_image/ocr.py", line 284, in supplement_element_with_table_extraction
2024-07-24T08:49:18.887488006Z     text_as_html = "" if tatr_cells == "" else cells_to_html(tatr_cells)
2024-07-24T08:49:18.887503751Z                                                ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-24T08:49:18.887511928Z   File "/home/notebook-user/.local/lib/python3.11/site-packages/unstructured_inference/models/tables.py", line 704, in cells_to_html
2024-07-24T08:49:18.887519618Z     cells = sorted(fill_cells(cells), key=lambda k: (min(k["row_nums"]), min(k["column_nums"])))
2024-07-24T08:49:18.887527508Z                    ^^^^^^^^^^^^^^^^^
2024-07-24T08:49:18.887534601Z   File "/home/notebook-user/.local/lib/python3.11/site-packages/unstructured_inference/models/tables.py", line 667, in fill_cells
2024-07-24T08:49:18.887542331Z     table_rows_no = max({row for cell in cells for row in cell["row_nums"]})
2024-07-24T08:49:18.887549813Z                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-07-24T08:49:18.887557089Z ValueError: max() arg is an empty sequence

Environment:

Unstructured API 0.0.72 deployed in remote machine
Local deployment lib versions
unstructured==0.14.6
unstructured-client==0.18.0
OS
Ubunut 22.04.02 LTS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in unstructured_inference/models/tables.py, especially fill_cells and cells_to_html, using the reported hi_res PDF-processing path as the reproduction context. Trace how empty cell data reaches max() and add a regression test for that input. Done means HTML table generation no longer raises ValueError for the reproduced case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.