fix(serializer): stop duplicating spanning cells in markdown/dataframe output#601
Open
scottf007 wants to merge 1 commit intodocling-project:mainfrom
Open
fix(serializer): stop duplicating spanning cells in markdown/dataframe output#601scottf007 wants to merge 1 commit intodocling-project:mainfrom
scottf007 wants to merge 1 commit intodocling-project:mainfrom
Conversation
…e output
The markdown table serializer and the legacy markdown/dataframe export
paths iterate `data.grid` and emit cell text at every grid position.
Because a TableCell with `col_span > 1` or `row_span > 1` occupies every
grid position it covers (with the same cell reference), this produces N
copies of the cell's text in the output instead of one.
Visible symptoms:
- A colspan=4 header like "KRYTERIA FORMALNE" rendered as four repeated
columns instead of one.
- A rowspan=2 cell like "Energy reduction" rendered twice in
consecutive rows of the markdown table.
- export_to_dataframe concatenated the parent header text with each
child header (e.g. "KRYTERIA FORMALNE.Lp.", "KRYTERIA FORMALNE.TAK").
Fix: in all three code paths (modern MarkdownTableSerializer.serialize,
legacy TableItem.export_to_markdown, TableItem.export_to_dataframe),
emit cell text only at the cell's origin position
(start_row_offset_idx, start_col_offset_idx). Spanned positions render
as empty strings. Underlying TableCell data is unchanged; only the
serialized presentation changes. Cells with col_span=1 and row_span=1
are unaffected because their single grid position equals their origin.
Regenerated affected groundtruth fixtures
(test/data/doc/2206.01062.yaml.md, *.paged.md, constructed_doc*.md.gt,
constructed_document.yaml.md). The diff in those files is precisely the
removed cell-content duplication.
Closes docling-project/docling#2862
Signed-off-by: scott <scott@fletchcorp.com>
Contributor
|
✅ DCO Check Passed Thanks @scottf007, all your commits are properly signed off. 🎉 |
Contributor
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🔴 Require two reviewer for test updatesWaiting for:
This rule is failing.When test data is updated, we require two reviewers
🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
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
The markdown table serializer and the legacy markdown / dataframe export paths iterate
data.gridand emit each grid cell's text. When aTableCellhascol_span > 1orrow_span > 1, the same cell reference occupies every grid position it covers, so iterating produces N copies of the cell's text in the output instead of one.The underlying
TableCelldata is correct (TableFormer emits one cell per merged region withcol_span/row_spanset). Only the serialized presentation duplicates.Visible symptoms
col_span=4header like `KRYTERIA FORMALNE` rendered as four repeated cells instead of one cell + three empties.row_span=2cell like `Energy reduction` rendered twice in consecutive rows of the markdown table.export_to_dataframe()concatenated the parent header text with each child header (e.g. `KRYTERIA FORMALNE.Lp.`, `KRYTERIA FORMALNE.TAK`).Fix
In all three code paths:
MarkdownTableSerializer.serialize(modern path)TableItem.export_to_markdown(legacy path)TableItem.export_to_dataframeemit cell text only at the cell's origin position (
start_row_offset_idx,start_col_offset_idx). Spanned positions render as empty string. Cells withcol_span=1androw_span=1are unaffected because their single grid position equals their origin.Test plan
Issues addressed
Closes docling-project/docling#2862 — `export_to_dataframe` produces duplicated cells when tables contain spanning cells. The dataframe path is fixed by this change.
Notes