← Back to Pull requests

fix(table): preserve native line cells when word cells are absent #5531

Closed
unknown closed this pull request without merging on Nov 26, 2026 21:54 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 02:35 UTC
Author

Keep native textline_cells from table_cluster.cells in _words_and_ocr_cells() when a PDF backend does not populate word_cells (such as PyPdfiumDocumentBackend).

Issue resolved by this Pull Request:
Resolves #5237

Checklist:

  • Documentation has been updated, if necessary.

  • Examples have been added, if necessary.

  • Tests have been added, if necessary.
  • Review evidence:

  • Before: PyPdfiumPageBackend.get_segmented_page() leaves word_cells=[] (has_words=False) and populates only textline_cells. When OCR keeps at least one cell in table_cluster.cells, _words_and_ocr_cells() returned only those OCR lines (len(tcells) > 0), bypassing the empty-token fallback in TableStructureModel.predict_tables() and dropping every native table cell. When paired with a word-level OCR plugin, OCR words over kept native lines were also not suppressed because native_words was empty.

  • After: _words_and_ocr_cells() retains uncovered native lines from cluster_cells alongside native word cells (mirroring the OCR line fallback), ignores whitespace-only word cells before coverage checks, and filters OCR words against the kept native cells. Existing behavior when native word_cells cover the table (e.g., docling-parse), in full-page OCR mode, and with word-level OCR plugins is preserved.

  • Reference data: No reference test data changed.

  • Verification:

  • - uv run --no-sync pytest tests/test_table_structure_model.py -v: 5 new regression tests fail on main (0f3564c) and all 7 tests pass after the fix.
    - uv run --no-sync pytest tests/test_table_structure_model.py tests/test_ocr_rects_dedup.py tests/test_ocr_options_force_full_page.py tests/test_skip_cell_extraction.py -v: 34 passed.
    - uv run --no-sync prek run --files docling/models/stages/table_structure/table_structure_model.py tests/test_table_structure_model.py: all hooks passed (ruff, ruff-format, ty, tach, tach-module-coverage, insert-license, max-lines).
    - Not run locally: ml_pdf_model end-to-end tests (tests/test_e2e_table_structure_ocr.py, pypdfium2 + TableFormer weights) because the local slim environment does not include pypdfium2 or ML model weights.

    Diff: 279 lines (+209 / -70) across 3 files Reviewer: yxshee Review duration: 5479m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 279 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.337
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5531"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.6% (MEDIUM) · Higher = larger blast radius
    39.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.1% · Safe to merge
    17.1%