Skip to content

fix: compare .label in predict_merges skip loop, not element object#153

Closed
Frank-Schruefer wants to merge 2 commits into
docling-project:mainfrom
Frank-Schruefer:fix/predict-merges-skip-label-comparison
Closed

fix: compare .label in predict_merges skip loop, not element object#153
Frank-Schruefer wants to merge 2 commits into
docling-project:mainfrom
Frank-Schruefer:fix/predict-merges-skip-label-comparison

Conversation

@Frank-Schruefer

Copy link
Copy Markdown
Contributor

Bug

In predict_merges, the while loop is intended to skip over interrupting elements (page headers, footers, tables, pictures, captions, footnotes) between two TEXT elements before deciding whether to merge them.

The loop condition compared the PageElement object itself against a list of DocItemLabel enum values:

while ind_p1 < len(sorted_elements) and sorted_elements[ind_p1] in [
    DocItemLabel.PAGE_HEADER,
    DocItemLabel.PAGE_FOOTER,
    ...
]:

Since a PageElement instance is never equal to a DocItemLabel enum value, this comparison always evaluates to False — the skip loop never advances and interrupting elements are never skipped.

Fix

Compare the element's .label attribute instead:

while ind_p1 < len(sorted_elements) and sorted_elements[ind_p1].label in [
    DocItemLabel.PAGE_HEADER,
    ...
]:

In predict_merges, the while loop intended to skip over non-text elements
(headers, footers, tables, pictures, captions, footnotes) compared the
PageElement object itself against a list of DocItemLabel enum values:

    sorted_elements[ind_p1] in [DocItemLabel.PAGE_HEADER, ...]

This comparison always evaluates to False, so the skip loop never
advanced — interrupting elements were never skipped. Fix by comparing
the element's label attribute instead:

    sorted_elements[ind_p1].label in [DocItemLabel.PAGE_HEADER, ...]

Signed-off-by: stone <frank.schruefer@t-online.de>
@github-actions

github-actions Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @Frank-Schruefer, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@nikos-livathinos nikos-livathinos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me. But the code should be properly formatted and pass all code-checks.

@nikos-livathinos nikos-livathinos self-requested a review April 7, 2026 09:22
Signed-off-by: stone <frank.schruefer@t-online.de>
@codecov

codecov Bot commented Apr 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nikos-livathinos

Copy link
Copy Markdown
Member

This PR is superseded by #156

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.

2 participants