Skip to content

fix(uspto): parse proportional and missing CALS colwidth - #3821

Closed
santhreal wants to merge 4 commits into
docling-project:mainfrom
santhreal:fix/uspto-table-colwidth
Closed

fix(uspto): parse proportional and missing CALS colwidth#3821
santhreal wants to merge 4 commits into
docling-project:mainfrom
santhreal:fix/uspto-table-colwidth

Conversation

@santhreal

Copy link
Copy Markdown
Contributor

The USPTO table parser strips only pt/mm from colwidth then casts to int/float. A proportional width like colwidth="1*" (standard CALS) reaches float("1*") and raises ValueError, and a <colspec> with no colwidth reaches re.sub("pt", "", None) and raises TypeError. Both crashes are caught at the call site (XmlTable.parse() is wrapped in try/except Exception), so every affected table is silently dropped from the output document.

This extracts the leading numeric magnitude instead, defaulting to 1.0 when the width is absent, so proportional and unit-less tables parse with correct relative offsets rather than being lost.

Repro against the real backend:

from docling.backend.xml.uspto_backend import XmlTable

xml = (
    '<table><tgroup cols="2">'
    '<colspec colname="1" colwidth="1*"/><colspec colname="2" colwidth="2*"/>'
    '<tbody><row><entry>a</entry><entry>b</entry></row></tbody>'
    '</tgroup></table>'
)
XmlTable(xml).parse()  # before: ValueError: could not convert string to float: '1*'

Added test_table_colwidth_variants covering proportional, unit-less, and fixed-pt (control) widths.

The USPTO table parser stripped only pt/mm units then cast colwidth to
int/float. A proportional width (1*, standard CALS) reached float(1*)
and raised ValueError, and a colspec with no colwidth reached re.sub(None)
and raised TypeError. Both crashes are caught at the call site, so every
affected table is dropped from the output document.

Extract the leading numeric magnitude instead, defaulting to 1.0 when the
width is absent, so proportional and unit-less tables parse with correct
relative offsets rather than being silently lost.

Signed-off-by: santhreal <64453045+santhreal@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

DCO Check Passed

Thanks @santhreal, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

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)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ceberam ceberam added bug Something isn't working xml issue related to supported schema-specific XML formats labels Jul 21, 2026

@ceberam ceberam 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.

Good catch @santhreal ! I've just added a minor styling comment.

Comment thread docling/backend/xml/uspto_backend.py Outdated
@ceberam

ceberam commented Jul 27, 2026

Copy link
Copy Markdown
Member

@santhreal could you fix the DCO? (your last commit was not sign), as well as the conflict with tests/test_backend_patent_uspto.py?

…width

Signed-off-by: santhreal <64453045+santhreal@users.noreply.github.com>

# Conflicts:
#	tests/test_backend_patent_uspto.py
…y.github.com>

I, santhreal <64453045+santhreal@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 82e7e7e

Signed-off-by: santhreal <64453045+santhreal@users.noreply.github.com>
@santhreal santhreal closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working xml issue related to supported schema-specific XML formats

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants