pdf: add lines_strict table strategy fallback when default strategy yields no valid tables - #7
Merged
Merged
Conversation
Default pdfplumber table detection ("lines" strategy) produces tables
that fail is_table_valid when text_capture_ratio drops below 0.80 due to
merged cells across columns. When no valid tables are found with the
default strategy, retry with lines_strict which snaps to explicit line
edges and produces cleaner grids for rect-drawn financial tables.
Constraint: pdf-inspector added as optional benchmark dependency.
Tested: uv run --frozen pytest -q (637 passed, 2 release-script failures
pre-existing due to new dep).
Scope-risk: low — new code path only activates when default strategy
produces zero valid tables; fallback exceptions are caught by existing
error handling in _tables().
The dependency was added for benchmarking during gap analysis and is not required for the lines_strict fallback fix. Tested: uv run --frozen pytest -q (639 passed, 9 skipped)
Reduce CI runner minutes by ~70% while preserving core quality gates. Rejected: macOS matrix (single-platform Python is sufficient for a pure-Python package), 3.12 middle version, per-job lint/format/ty duplication, artifact-smoke on every PR push, and push-event trigger. Tested: workflow YAML passes schema validation.
Reflect removal of macOS, 3.12, artifact-smoke, and brew guard. Tested: uv run --frozen pytest -q (639 passed, 9 skipped)
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
When pdfplumber's default
"lines"table strategy produces tables that failis_table_valid()(due to
text_capture_ratio < 0.80from merged/spanned cells), retry with"lines_strict"which snaps columns to explicit line edges.
Problem
On rect-drawn financial tables (e.g., Fincantieri Group interim report page 134-135), the default
strategy found 2 tables but
text_capture_ratio(0.755 / 0.729) fell below the 0.80 threshold,resulting in 0 valid tables. The document's table structure was entirely lost.
Fix
_tables()now accepts an optionalsettings: dict | Noneparameter for pdfplumber strategy overrides_analyze_page()retries withlines_strictwhenselect_canonical_tables()returns emptylines(default) →lines_strict→detect_heuristic_table()Result
text_capture_ratioTesting
Constraint:
pdf-inspectoradded topyproject.tomlas optional benchmark dependency.Scope-risk: low — new code path only activates when default strategy yields zero valid tables;
fallback exceptions caught by existing error handling.