Skip to content

Distinguish missing cells from empty strings on request - #265

Open
rayw-lab wants to merge 1 commit into
dimastbk:masterfrom
rayw-lab:codex/optional-empty-as-none
Open

rayw-lab wants to merge 1 commit into
dimastbk:masterfrom
rayw-lab:codex/optional-empty-as-none

Conversation

@rayw-lab

@rayw-lab rayw-lab commented Nov 23, 2026 •

Copy link
Copy Markdown

Closes #260.

A missing cell and a formula whose cached result is an empty string both come back as "" today. This adds an optional empty_as_none=True keyword to to_python() and iter_rows() so callers can distinguish them in a single read. Missing cells and padding become None. Formula results keep their string value, and error cells keep their existing behavior. Both methods keep their current defaults.

The regression tests read XLS and XLSX fixtures through both methods and cover leading padding. I built a CPython 3.13 wheel on macOS arm64 and ran the Python suite against the installed wheel: 72 passed, 1 expected failure. Clippy, rustfmt, mypy and stubtest also passed.

Summary by CodeRabbit

  • New Features

    • Added an empty_as_none option to sheet conversion and row iteration. Empty cells return None when enabled; by default, they continue to return "".
    • The option also applies to included leading empty rows and columns. Empty strings and error values retain their existing behavior.
  • Documentation

    • Added examples and guidance for handling empty cells with both conversion methods.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The sheet conversion methods add an empty_as_none option. By default, empty cells convert to empty strings; when enabled, empty cells convert to None. The option applies to to_python() and iter_rows(), including padded cells.

Changes: Empty-cell conversion

Layer / File(s) Summary
Conversion option and behavior
src/types/sheet.rs, python/python_calamine/_python_calamine.pyi, tests/test_empty_cells.py, README.md
to_python() and iter_rows() accept empty_as_none, which defaults to False. When enabled, empty cells and padded cells convert to None. Type declarations, tests, and documentation cover the option. Empty strings and error-value conversion retain their existing behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature · Severity of issue fixed: Medium

Suggested reviewers: dimastbk

Merge Risk: Minimal · up to e9c4c · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Distinguish missing cells from empty strings on request" matches the main change. The PR adds an opt-in empty_as_none=True keyword to to_python() and iter_rows(). With this option, empty an…
Linked Issues check Passed [#260] requests an opt-in way for to_python() and iter_rows() to return None for blank cells while keeping empty-string results as ''. The change adds empty_as_none (keyword-only, default `f…
Out of Scope Changes check Passed All changed areas connect to #260. src/types/sheet.rs implements the opt-in empty_as_none behavior for to_python() and iter_rows(). python/python_calamine/_python_calamine.pyi declares the m…
Full details: Title check

Explanation

The title "Distinguish missing cells from empty strings on request" matches the main change. The PR adds an opt-in empty_as_none=True keyword to to_python() and iter_rows(). With this option, empty and padded cells return None, while empty-string results stay "". The title states the opt-in nature ("on request"), and the changeset in the summary matches it. No web search was needed for this check.

Full details: Linked Issues check

Explanation

[#260] requests an opt-in way for to_python() and iter_rows() to return None for blank cells while keeping empty-string results as ''. The change adds empty_as_none (keyword-only, default false) to both methods in src/types/sheet.rs. With the option set, cell_value maps Data::Empty to None. Formula results that evaluate to an empty string remain Data::String("") and keep their "" value. Padding rows built by CalamineCellIterator follow the same rule. Error cells use the existing CellValue conversion. The default behavior is unchanged, which addresses the backward-compatibility concern in the issue. The .pyi stub adds matching overloads. tests/test_empty_cells.py covers XLS and XLSX reads through both methods, including leading empty rows and columns. The summary does not show the test fixtures (tests/data/empty-string.xls and .xlsx). Those files match the ignored-file rules, so their contents were not reviewed. The regression test results were not independently verified. The implementation evidence is sufficient for the coding requirement.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #260. src/types/sheet.rs implements the opt-in empty_as_none behavior for to_python() and iter_rows(). python/python_calamine/_python_calamine.pyi declares the matching overloads and the _CellValue type. README.md documents the new keyword and its default. tests/test_empty_cells.py tests the new behavior. The to_python docstring change in the stub is a documentation edit tied to the same signature change. No unrelated changes appear in the summary. The change does not alter error-cell conversion or the default output, as the PR description states. The ignored fixture files were not reviewed, but they are test inputs for the in-scope tests and do not add out-of-scope behavior.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each blank with care,
And finds None waiting there.
An empty string stays as it was,
Rows keep their shape without a pause.
The sheet returns its cells just right.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9acaab67-a9c4-4c8c-ba8d-7d8bc95f37d3
Commits

Reviewing files that changed from the base of the PR and between 4a2b067 and e9c4cbf.

Files ignored due to path filters: 2

  • tests/data/empty-string.xls is excluded by !**/*.xls
  • tests/data/empty-string.xlsx is excluded by !**/*.xlsx
Files selected for processing: 4

  • README.md
  • python/python_calamine/_python_calamine.pyi
  • src/types/sheet.rs
  • tests/test_empty_cells.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@rayw-lab

Copy link
Copy Markdown
Author

The only failing CI job is the Linux i686 wheel build. Its log stops while installing libatomic because vault.centos.org could not be resolved, before the wheel build starts. The same DNS failure occurred in an earlier run on another PR.

I tried to rerun the failed job, but GitHub requires repository admin rights. Could a maintainer rerun the i686 job when convenient?

This branch has not been deployed

No deployments
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.

Distinguish empty-string cells from blank cells

1 participant