Skip to content

Distinguish empty-string cells from blank cells #260

Open

Description

@rad-pat

to_python() and iter_rows() return '' for both a blank cell and a cell holding an empty string, so callers can't tell them apart. That matters when importing data where an empty string and a missing value mean different things (e.g. mapping blanks to NULL but keeping '').

import xlwt
from python_calamine import CalamineWorkbook

book = xlwt.Workbook()
sheet = book.add_sheet("s")
sheet.write(0, 0, xlwt.Formula('""'))  # A1: formula whose result is an empty string
sheet.write(0, 1, "x")
sheet.write(1, 1, "x")                 # A2: no cell at all
book.save("t.xls")

print(CalamineWorkbook.from_path("t.xls").get_sheet_by_index(0).to_python())
# [['', 'x'], ['', 'x']]

Tested on 0.9.1. xlrd reports A1 as XL_CELL_TEXT and A2 as XL_CELL_EMPTY.

The calamine crate does keep the difference in its XLS reader (Data::String("") vs an absent cell, in 0.37.0). It seems to be lost in CellValue::Empty => "" in src/types/cell.rs.

Since changing the default would affect existing callers, could this be opt-in, for example a keyword on to_python() / iter_rows() that returns None for blank cells? This is close to #105 / #258 on error cells, which are also indistinguishable from blanks, so one typed-value approach might cover both.

Activity

  1. rayw-lab commented on Nov 22, 2026

    @rayw-lab

    I reproduced this with synthetic XLS and XLSX samples. With python-calamine 0.9.1, both to_python() and iter_rows() return '' for the XLS formula's empty-string result and an absent cell. A separate Rust probe using calamine 0.38.0 (the current master dependency) reads the same XLS and a synthetic XLSX as Data::String("") for the empty-string formula result and Data::Empty for the absent cell.

    One detail matters for compatibility: the current Python conversion also maps error values to CellValue::Empty. Simply changing that variant to None would therefore change error results too, in addition to overlapping with #258.

    Would you prefer an opt-in empty_as_none=False keyword on both to_python() and iter_rows(), which returns None only for underlying Data::Empty (including padding) while leaving existing defaults and error handling unchanged? Or should this wait for a broader typed-cell API alongside #258? I can prepare tests for the default and opt-in paths, including leading empty rows and both XLS and XLSX.

  2. rad-pat commented on Nov 23, 2026

    @rad-pat
    Author

    Thanks for reproducing it, and for catching the error mapping. I'd go with the opt-in empty_as_none now rather than waiting for a typed-cell API. It's additive, it doesn't block a typed API later, and leaving errors alone keeps it separate from #258.

    None for padding is right for our use too, since an absent cell and a padded one both mean "no value". Today we re-read the workbook with xlrd/openpyxl just to find the empty-string cells, and this keyword would let us drop that pass.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions