Repository navigation
fix(xlsx): preserve saved Excel error values - #2766
Deepika Mundla (dpka2206) wants to merge 1 commit into
Conversation
|
@microsoft-github-policy-service agree |
Pandas maps Excel error cells to NaN before Markdown is rendered, so a #DIV/0! cell looks the same as a blank. Restore the saved error token after the sheet is formatted.
e1496b2 to
4323e63
Compare
Rahul (rahul05ranjan)
left a comment
There was a problem hiding this comment.
I verified the core approach independently with pandas 2.2.3/openpyxl 3.1.5: an error cell like #DIV/0! does surface as NaN in the DataFrame (so the post-render patch is the only place it can be recovered), and the rows[cell.row - 1][cell.column - 1] indexing held up in the shapes I tried — including ones your test doesn't cover:
- a leading fully-blank row above the header (pandas keeps it as an
Unnamedheader and the tr/row mapping stays 1:1), - a fully-blank row in the middle (kept as an all-NaN data row, still 1:1),
- a trailing row whose only value is the error itself (pandas sees all-NaN but keeps the row, so the
#REF!lands in the right cell).
So the correctness hinges on pandas keeping every worksheet row as exactly one <tr>. That invariant holds in 2.2.x, but note it's an implementation detail of read_excel, not a contract — if pandas ever starts trimming trailing all-NaN rows (it has flip-flopped on that historically), rows[cell.row - 1] becomes an IndexError and the whole conversion fails on a file whose previous behavior was just a stray NaN. Since the errors list is usually tiny, a cheap belt-and-braces guard like if cell.row - 1 < len(rows): ... (or skipping out-of-range cells) would keep a bad sheet producing degraded-but-valid output instead of a crash. Not a blocker, just hardening.
Nit: the three cases above are exactly the ones a future pandas bump would break first — worth adding one regression test with a blank leading row so the alignment assumption is pinned in CI rather than implicit.
…R watermark Ten new upstream PRs, none adopted. Four are real fixes (xlsx error values, ipynb string source, RSS 1.0, data URI fragment) whose defects reproduce on this fork but are outside the Windows/CJK exception class; six are noise or re-submissions of already-adopted microsoft#1913. Reasons and revisit triggers are in docs/DECISIONS.md. PR watermark 2765 -> 2775. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Summary
#DIV/0!and#REF!were converted toNaNbecause pandas dropsdata_type == "e"values inside its openpyxl reader, before Markdown is built.NaN.Test plan
pytest packages/markitdown/tests/test_xlsx.py(26 passed)#DIV/0!,#REF!,#VALUE!,#N/A,#NUM!,#NAME?, and#NULL!, keeps42.0, and keeps the blank cell asNaN