Skip to content

fix(tables): keep every header row when the column header starts below the first row - #526

Open
chrikrah wants to merge 1 commit into
Unstructured-IO:mainfrom
chrikrah:fix/align-headers-header-row-offset
Open

chrikrah wants to merge 1 commit into
Unstructured-IO:mainfrom
chrikrah:fix/align-headers-header-row-offset

Conversation

@chrikrah

@chrikrah chrikrah commented Oct 12, 2026 •

Copy link
Copy Markdown

align_headers in unstructured_inference/models/tables.py:487 fills in the rows above a column header with range(header_row_nums[0] + 1), so the first header row appears twice. The loop that follows stops at the repeat. Every header row after the first one then comes out as a body row. In cells_to_html that row turns into <td> cells in <tbody>, so text_as_html loses the second header row.

A header box over rows 1 and 2 of a four-row table:

$ python align_demo.py   # at 158db67
[{'bbox': [0, 0, 100, 20]}]
[True, True, False, False]

With range(header_row_nums[0]):

$ python align_demo.py
[{'bbox': [0, 0, 100, 30]}]
[True, True, True, False]

The docstring asks for the convex hull of the rows the header intersects. The code extends that up to row 0, so rows 0 to 2 here. A header that starts on row 0, or covers a single row, gives the same result before and after. The line came from microsoft/table-transformer's postprocess.py, and that repository is archived, so this copy is the only place to fix it. No issue exists for this.

Verification

$ python -m pytest -q test_unstructured_inference/models/test_tables.py
60 passed in 13.47s

Baseline on 158db67 is 57 passed, so the delta is the 3 new cases. I restored tables.py from 158db67 and kept the tests, which gives 1 failed, 59 passed. The failing case is the header over rows 1 and 2. ruff check and ruff format --check (0.15.10) are clean on both files, and make check-version passes.

# not run: the rest of test_unstructured_inference, which loads the detection models

The CHANGELOG entry takes 1.6.15, which my #525 also claims. I'll rebase whichever one merges second. @badGarnet, could you review this when you next look at table post-processing?

View guided diff

…w the first row

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>
@chrikrah
chrikrah force-pushed the fix/align-headers-header-row-offset branch from 9825156 to 6276a38 Compare November 5, 2026 07:31

@chrikrah chrikrah left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cragwolfe rebased onto 86fc917, so the CHANGELOG and version conflict is gone. It takes 1.6.18 for now, which #524, #516 and #517 also claim, so I'll re-bump to whatever version is free when this gets picked up.

$ CI=true uv run --locked --no-sync pytest -m "not slow" test_unstructured_inference -q
387 passed, 1 skipped, 4 deselected     # main 86fc917: 384 passed, 1 skipped
$ git show 86fc917:unstructured_inference/models/tables.py > unstructured_inference/models/tables.py
$ uv run --locked --no-sync pytest test_unstructured_inference/models/test_tables.py -q
1 failed, 59 passed

The fix is one range bound in align_headers. Is a second header row going missing from text_as_html something you've seen on real tables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant