fix(doctags): tolerate inverted bbox in DocumentToken.get_location#628
Open
assinscreedFC wants to merge 1 commit into
Open
Conversation
get_location() asserted bbox[0] <= bbox[2] and bbox[1] <= bbox[3], but the following min()/max() calls already emit correctly-ordered location tokens regardless of input ordering. The asserts were therefore redundant while still crashing export_to_doctags(add_location=True) on near-degenerate elements (e.g. a near-zero-height layout-model artifact whose regressed bbox is slightly inverted). This bites long documents, where the probability of at least one such element grows with page count. Drop the redundant asserts in both docling_core/types/doc/tokens.py and docling_core/types/legacy_doc/tokens.py so the existing min()/max() normalization handles inverted input. Fixes docling-project#620 Signed-off-by: ANIS <119749586+assinscreedFC@users.noreply.github.com>
Contributor
|
✅ DCO Check Passed Thanks @assinscreedFC, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DocumentToken.get_location()assertedbbox[0] <= bbox[2]andbbox[1] <= bbox[3], but themin()/max()calls right below already emit correctly-ordered location tokens regardless of input ordering. The asserts were redundant with that normalization, yet still crashedexport_to_doctags(add_location=True)on near-degenerate elements (e.g. a near-zero-height layout-model artifact whose regressed bbox is slightly inverted):The probability of hitting at least one such element grows with page count, so it bites long documents in particular.
Fix
Drop the two redundant asserts in both
docling_core/types/doc/tokens.pyanddocling_core/types/legacy_doc/tokens.py. The existingmin()/max()logic already produces correctly-ordered output, so inverted input is normalized rather than fatal.Tests
Added
test/test_tokens.py:get_locationall no longer raise and yield the same tokens as their normalized counterparts.Closes #620