Preserve explicit table lines outside the natural edge span (fixes #1335)#1371
Open
Cyberfilo wants to merge 1 commit into
Open
Preserve explicit table lines outside the natural edge span (fixes #1335)#1371Cyberfilo wants to merge 1 commit into
Cyberfilo wants to merge 1 commit into
Conversation
When `extract_table` is called with `vertical_strategy="explicit"` (or `horizontal_strategy="explicit"`), the user-supplied lines define the column (resp. row) boundaries. Edges of the opposite orientation are still derived from text clustering or detected lines, and `words_to_edges_h` / `words_to_edges_v` only span the range of the underlying objects. When an explicit line sits outside that span — common when the leftmost or rightmost column is narrow, right-aligned, or contains only short text — `edges_to_intersections` rejects the intersection and the entire column collapses into a neighbour. Extend the horizontal edges to cover the x-range of any explicit vertical lines (and symmetrically for explicit horizontals) before computing intersections. Explicit edges already span the full page, so this only widens edges derived from words or page lines; no other tables are affected. Fixes jsvine#1335.
Author
|
@jsvine @samkit-jain please review |
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.
What
When
page.extract_table(...)is called withvertical_strategy="explicit"(orhorizontal_strategy="explicit"), the user-supplied lines define the column / row boundaries. Edges of the opposite orientation are still derived from text clustering or detected page lines, and those are only as wide as the underlying objects.words_to_edges_h(and thelinesvariants for horizontal edges) span justmin_x0..max_x1of the rows they detect.edges_to_intersectionsthen keeps only the vertical edges whosex0falls inside[h.x0 - x_tol, h.x1 + x_tol]. When an explicit vertical line sits outside that span — common when the leftmost or rightmost column is narrow, right-aligned, or contains only short / multi-line text — the intersection is rejected and the entire column collapses into its neighbour (or disappears entirely if it is the only one beyond the span).Fix
In
TableFinder.get_edges(), after the base + explicit edges are concatenated, extend each horizontal edge'sx0/x1to cover the x-range of any explicit vertical lines (and symmetrically extend vertical edges'top/bottomto cover any explicit horizontals).Explicit edges already span the full page when supplied as floats, and span their declared bbox when supplied as dicts — so this only ever widens edges derived from words or page lines, never narrows or moves anything. Tables that do not use explicit lines are untouched.
Repro / test
Added
test_issue_1335_explicit_outside_text_spanintests/test_table.py. It constructs a three-row, three-column layout with a narrow last column (text ends ~130 px before the rightmost explicit vertical) and asserts that:Without the patch, only the inner two explicit verticals produce intersections and the table collapses to a single column. Running the new test against
develop:With the patch:
Verification
make tests— 165 passed (the pre-existingtest_repair.py::test_from_issue_932failure on systems without Ghostscript is unchanged).make lint— clean (flake8, mypy --strict, black --check, isort --check).## UnreleasedinCHANGELOG.mdand added myself to the contributors list perCONTRIBUTING.md.Fixes #1335.