Skip to content

Commit

Permalink
fix: consider #NUM! error type as None (#321)
Browse files Browse the repository at this point in the history
* consider `#NUM!` error type as `None`

* Update python/tests/test_fastexcel.py

Co-authored-by: Luka Peschke <mail@lukapeschke.com>
  • Loading branch information
sphuber and lukapeschke authored Jan 13, 2025
1 parent 9086487 commit 02a9b8a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Binary file not shown.
9 changes: 9 additions & 0 deletions python/tests/test_fastexcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,15 @@ def test_null_values_in_cells() -> None:
pd_assert_frame_equal(sheet.to_pandas(), pd_expected)


def test_invalid_value_num() -> None:
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-invalid-cell-value-num.xlsx"))
sheet = excel_reader.load_sheet(0)

expected = {"Column": [8.0, None]}
pd_assert_frame_equal(sheet.to_pandas(), pd.DataFrame(expected))
pl_assert_frame_equal(sheet.to_polars(), pl.DataFrame(expected))


def test_null_column_is_nullable() -> None:
sheet = fastexcel.read_excel(path_for_fixture("null-column.xlsx")).load_sheet(0)
assert sheet.to_arrow().schema.field("nullonly").nullable is True
Expand Down
2 changes: 1 addition & 1 deletion src/types/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn get_cell_dtype<DT: CellType + Debug + DataType>(
match cell.get_error() {
// considering cells with #N/A! or #REF! as null
Some(
CellErrorType::NA | CellErrorType::Value | CellErrorType::Null | CellErrorType::Ref,
CellErrorType::NA | CellErrorType::Value | CellErrorType::Null | CellErrorType::Ref | CellErrorType::Num,
) => Ok(DType::Null),
Some(err) => Err(FastExcelErrorKind::CalamineCellError(err.to_owned()).into()),
None => Err(FastExcelErrorKind::Internal(format!(
Expand Down

0 comments on commit 02a9b8a

Please sign in to comment.