fix(md): size table to the widest row, not the header - #3823
Conversation
The Markdown table parser set num_cols from the header row's cell count. When a body row has more cells than the header, those extra cells stayed in table_cells but their column index fell outside num_cols, so every exporter (markdown, dataframe) dropped them and the data was silently lost. Size num_cols to the widest row instead, matching the CSV backend, so wider body rows keep all their cells on export. Signed-off-by: santhreal <64453045+santhreal@users.noreply.github.com>
|
✅ DCO Check Passed Thanks @santhreal, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks @santhreal for your interest in Docling and your contribution. However, the changes on this PR are not a fix. Docling behaves as designed in the scenario described in this issue.
This is exactly how Docling handles these edge cases. In your example,
Please, follow the contributor's guidelines and open an issue if you identify a bug before suggesting a PR to avoid this type of situations. |
The Markdown table parser sets
num_colsfrom the header row's cell count (num_cols = len(result_table[0])). When a body row has more cells than the header, the extra cells stay intable_cellsbut their column index falls outsidenum_cols, soexport_to_markdownandexport_to_dataframebuild a header-width grid and silently drop them.This sizes
num_colsto the widest row instead, matching the CSV backend (num_cols = max(len(row) ...)), so wider body rows keep all their cells on export. Thedefault=0also removes a latentresult_table[0]IndexError on an empty table.Repro:
Added
test_convert_table_body_row_wider_than_header.Distinct from the trailing-pipe splitting in #3817 and the cell-duplication fix in #3781; this is the
num_colssizing on a different line.