Skip to content

[utils] Display page exports read back from a JSON file - #2168

Merged
felixdittrich92 merged 1 commit into
mindee:mainfrom
MohammadHijjawi97:fix-visualize-json-geometries
Oct 13, 2026
Merged

felixdittrich92 merged 1 commit into
mindee:mainfrom
MohammadHijjawi97:fix-visualize-json-geometries

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown
Contributor

A page export saved with json.dump and loaded back stores every geometry as lists, not tuples. create_obj_patch and rect_patch only accepted tuples, so displaying such an export failed:

import json
from doctr.io import Document

restored = Document.from_dict(json.load(open("results.json")), pages=pages)
restored.pages[0].show()
# ValueError: invalid geometry format

The same happens when the loaded dict goes straight to visualize_page or visualize_kie_page. render(), synthesize() and the other exports already work on the restored page; only the display failed.

This PR accepts lists as well as tuples in create_obj_patch and rect_patch. Invalid shapes still raise ValueError.

Tests:

  • test_visualize_json_exports: JSON round trip of a page with straight boxes, a rotated polygon and layout regions, in interactive and static modes, checking the same patches and labels as the tuple export, plus a KIE page.
  • test_page_from_dict_restores_the_image now also calls .show() on a page restored from JSON.

Both fail on main and pass with the fix. ruff check, ruff format --check and mypy doctr/ pass.

Any feedback is welcome 🤗

A page export saved with json.dump and loaded back stores every geometry
as lists instead of tuples. create_obj_patch and rect_patch only accepted
tuples, so visualize_page, visualize_kie_page and Page.show raised
"invalid geometry format" on such exports, e.g. after Page.from_dict on a
saved JSON file. Accept lists as well.
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.60%. Comparing base (fcff70c) to head (53edba9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2168      +/-   ##
==========================================
+ Coverage   97.55%   97.60%   +0.05%     
==========================================
  Files         170      170              
  Lines       10668    10740      +72     
==========================================
+ Hits        10407    10483      +76     
+ Misses        261      257       -4     
Flag Coverage Δ
unittests 97.60% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixdittrich92 felixdittrich92 self-assigned this Oct 13, 2026
@felixdittrich92 felixdittrich92 added type: bug Something isn't working module: utils Related to doctr.utils ext: tests Related to tests folder labels Oct 13, 2026
@felixdittrich92 felixdittrich92 added this to the 1.2.0 milestone Oct 13, 2026

@felixdittrich92 felixdittrich92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @MohammadHijjawi97 LGTM 👍

@felixdittrich92
felixdittrich92 merged commit 7b91803 into mindee:main Oct 13, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: tests Related to tests folder module: utils Related to doctr.utils type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants