markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

XLSX/XLS: whole numbers render as "1.0" when the column contains a blank cell

Open ManoharPaturi opened this issue 2 months ago • 1 comments

Description

In XLSX/XLS conversion, a single blank cell forces pandas to read its column as float64, so every whole number in that column renders with a .0 suffix, inconsistent with clean columns beside it:

# sheet: A1='count', A2=1, A3 blank, A4=2
from markitdown import MarkItDown, StreamInfo
...
'| count |',
'| 1.0 |',
'| NaN |',
'| 2.0 |',

Expected the integer rendering of clean columns: 1, 2.

Reproduction

import io
from openpyxl import Workbook
from markitdown import MarkItDown, StreamInfo

wb = Workbook(); ws = wb.active
ws['A1'] = 'count'; ws['A2'] = 1; ws['A3'] = None; ws['A4'] = 2
buf = io.BytesIO(); wb.save(buf); buf.seek(0)
print(MarkItDown().convert_stream(buf, stream_info=StreamInfo(extension='.xlsx')).markdown)

No network or fixture needed.

Notes

Distinct from the NaN-noise discussion in #2124 / #2286: simulating their patch still renders 1.0 for a numeric-header/data-only sheet, so the float64 promotion is a separate defect.

Environment

markitdown main (cc0ca9e), Python 3.12

ManoharPaturi avatar Sep 13 '26 16:09 ManoharPaturi

Root cause, for anyone else who lands here: _xlsx_converter.py reads the sheet with pd.read_excel(...), which applies pandas' default missing-value handling. A blank cell is read as a missing value, so the column is promoted to float64 and the remaining whole numbers render as 2.0.

Reading the raw cell values instead (keep_default_na=False) fixes it. I checked that reading every column as object also removes the .0, but it appends a time component to dates (2024-01-05 becomes 2024-01-05 00:00:00) and collapses small floats to 0.0, so it is not a safe substitute.

PR: #2535. It also fixes #2498, which turns out to have the same NA, NULL and None are in pandas' default na_values list.

shiyuanyeming-hub avatar Sep 18 '26 15:09 shiyuanyeming-hub