Skip to content

fix(xlsx): preserve literal NA, NULL strings and blank cells in Excel conversion (#2498) - #2922

Open
Techsynx (Techsynx) wants to merge 1 commit into
microsoft:mainfrom
Techsynx:fix/2498-excel-literal-na-blanks
Open

Techsynx (Techsynx) wants to merge 1 commit into
microsoft:mainfrom
Techsynx:fix/2498-excel-literal-na-blanks

Conversation

@Techsynx

Copy link
Copy Markdown

Fixes #2498

Description

In Excel conversion (XlsxConverter and XlsConverter), cells containing literal string tokens such as "NA", "NULL", "None", "n/a", or "nan", as well as blank cells and integers in columns with empty cells, were converted to "NaN" (e.g., | NaN | NaN | NaN | instead of | NA | NULL | |).

Root Cause

pd.read_excel() defaults to keep_default_na=True, which parses NA-like string tokens into np.nan and promotes columns with missing values to float64 (turning integers like 1 into 1.0 and empty cells into "NaN").

Solution

  • Pass keep_default_na=False across all pd.read_excel() calls in packages/markitdown/src/markitdown/converters/_xlsx_converter.py (openpyxl standard, openpyxl legacy showZeroes repair fallback, and xlrd reader).
  • Added comprehensive unit tests in packages/markitdown/tests/test_xlsx.py verifying:
    • Standard XLSX conversion preserves literal "NA", "NULL", "None", "n/a", "nan", integer numbers, and blank cells without emitting "NaN".
    • Repaired legacy showZeroes XLSX conversion preserves literal tokens and blank cells.
    • XLS conversion preserves literal tokens, integer values, and blank cells without emitting "NaN".
  • Verified with black --check and passing test suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Excel conversion replaces literal NA/NULL strings and blank cells with NaN

1 participant