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

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions