Repository navigation
fix(xlsx): preserve saved Excel error cells - #2732
Lubai (sunxiuguo) wants to merge 1 commit into
Conversation
Bicheng (BichengWang)
left a comment
There was a problem hiding this comment.
Reviewed a65d8788befe29cf5a14a30ddb3e7e5b3d0f81a7. Restoring saved errors after to_html() keeps pandas' existing numeric/date formatting while recovering the error values and their cell positions. Reusing ExcelFile.book also preserves the data-only behavior for cached formula errors; this does not evaluate formulas.
I reproduced the regression against current main 21d9c1d01ecc12538dab19811fd247ef2f96ef60: the 22 added cases give 20 failures and two passing empty-error controls with the main-branch converter. At this PR head, GITHUB_ACTIONS=1 python -m pytest tests/test_xlsx.py tests/test_html.py -q -p no:cacheprovider passes all 81 tests. An additional 26 generated workbook checks passed: errors at rows 1/2/5/11 and columns 1/3/7 with trailing data, an error-only header, HTML-shaped ordinary text, and borrowed-stream lifetime.
No blocking correctness issue found in this diff. Validation was offline on macOS / Python 3.12.15 with pandas 3.0.6 and openpyxl 3.1.5; I did not run the full suite or platform matrix. The full extras could not be installed offline because Mammoth >=1.12.2 was absent from cache, and the pinned Black 26.10.1 was also unavailable offline.
|
@microsoft-github-policy-service agree |
Fixes #2728.
Saved Excel error cells currently become pandas NaN values, so the Markdown loses the distinction between an error and a blank cell. This restores the saved error text without evaluating formulas.
Changes
ExcelFile.bookto locate nonempty error cells, including cached formula errors and error-valued headers.to_html()can otherwise change dates or round small nonzero floats to0.0.This is deliberately separate from literal NA-text handling in #2499, number-format/precision proposals, and formula calculation.
Validation
On current main
3cf47504plus this patch, isolated Linux / Python 3.12:hatch test --python 3.12: 1072 passed, 57 skipped (repository CI-mode skips; no service credentials; exiftool unavailable).pytest tests/test_xlsx.py tests/test_html.py -q: 81 passed.pre-commit run --all-files: passed, with the current Black 26.10.1 pin.Independent synthetic checks also covered header-only sheets, stream offsets, nonerror rendering, and escaped HTML-shaped cell values. These are automated checks, not Excel GUI acceptance or a multi-version/platform matrix.
Cost
This adds a second read-only worksheet scan. Sheets containing errors also need an HTML parse/serialization; sheets without errors retain the original HTML. A single 2,000×12 synthetic observation measured read-plus-HTML at 1.38→1.57 seconds without errors and 0.44→2.58 seconds with all data cells errors. These concurrent-run measurements are illustrative, not a performance guarantee.