Skip to content

fix(ocr): keep tesseract CLI words like "N/A" and numbers verbatim - #4536

Merged
PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
wak327:fix/tesseract-cli-keep-na-and-numeric-words
Oct 7, 2026
Merged

PeterStaar-IBM merged 1 commit into
docling-project:mainfrom
wak327:fix/tesseract-cli-keep-na-and-numeric-words

Conversation

@wak327

@wak327 wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

TesseractOcrCliModel._run_tesseract parsed tesseract's TSV output with pandas' default NA handling and type inference:

  • recognized words such as N/A, NA, None, null or nan were read as NaN and then dropped by the notna() filter;
  • in an OCR region where every word is numeric, the text column was inferred as float, so 007 became 7.0 and 2024 became 2024.0.

The read_csv call now passes dtype={"text": str} and keep_default_na=False, so the text column holds exactly what tesseract printed. Rows without text are still removed by the existing empty-string filter. The numeric columns are always populated in tesseract's TSV, so they are unaffected.

The new test feeds _run_tesseract the TSV tesseract prints for Price N/A NA None null nan and for 007 2024 12 (through a patched subprocess.run, like the existing language tests) and checks the words come back unchanged. On main the first case returns only ['Price'] and the second [7.0, 2024.0, 12.0].

Issue resolved by this Pull Request:
Resolves #4535

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

pd.read_csv parsed tesseract's TSV with the default NA handling and type
inference, so words such as "N/A", "None" or "null" became NaN and were
filtered out, and an OCR region with only numeric words came back as
floats ("007" -> "7.0"). Read the text column as plain strings.

Resolves docling-project#4535

Signed-off-by: Waleed Khalid <wak327@gmail.com>
@wak327

wak327 commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@dolfim-ibm @cau-git could you take a look? The TSV parsing comes from the original tesseract CLI model (#118). The str(text) added later for the crash in #877 kept conversions running, but the words were already lost or changed at read_csv. The fix is two keyword arguments on that call.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 3, 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 Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dolfim-ibm dolfim-ibm 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.

lgtm

@PeterStaar-IBM
PeterStaar-IBM merged commit 4faef5b into docling-project:main Oct 7, 2026
26 checks passed
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.

Tesseract CLI OCR drops words like "N/A" and "None" and turns numeric words into floats

3 participants