diff --git a/python/tests/fixtures/sheet-with-na.xlsx b/python/tests/fixtures/sheet-with-na.xlsx index e098fc9..f5b0bd8 100644 Binary files a/python/tests/fixtures/sheet-with-na.xlsx and b/python/tests/fixtures/sheet-with-na.xlsx differ diff --git a/python/tests/test_fastexcel.py b/python/tests/test_fastexcel.py index 69660a9..632a491 100644 --- a/python/tests/test_fastexcel.py +++ b/python/tests/test_fastexcel.py @@ -477,6 +477,20 @@ def test_sheet_with_na(): pl_assert_frame_equal(sheet.to_polars(), pl.DataFrame(expected)) +def test_sheet_with_ref(): + """Test reading a sheet with #REF! cells. For now, we consider them as null""" + excel_reader = fastexcel.read_excel(path_for_fixture("sheet-with-na.xlsx")) + sheet = excel_reader.load_sheet("Broken refs") + + assert sheet.name == "Broken refs" + assert sheet.height == sheet.total_height == 2 + assert sheet.width == 1 + + expected = {"numbers": [1.0, None]} + pd_assert_frame_equal(sheet.to_pandas(), pd.DataFrame(expected)) + pl_assert_frame_equal(sheet.to_polars(), pl.DataFrame(expected)) + + @pytest.mark.parametrize("excel_file", ["sheet-null-strings.xlsx", "sheet-null-strings-empty.xlsx"]) def test_null_strings(excel_file: str): excel_reader = fastexcel.read_excel(path_for_fixture(excel_file)) diff --git a/src/types/dtype.rs b/src/types/dtype.rs index dfbeecc..1f30306 100644 --- a/src/types/dtype.rs +++ b/src/types/dtype.rs @@ -159,8 +159,10 @@ fn get_cell_dtype( Ok(DType::Null) } else if cell.is_error() { match cell.get_error() { - // considering cells with #N/A! as null - Some(CellErrorType::NA | CellErrorType::Value | CellErrorType::Null) => Ok(DType::Null), + // considering cells with #N/A! or #REF! as null + Some( + CellErrorType::NA | CellErrorType::Value | CellErrorType::Null | CellErrorType::Ref, + ) => Ok(DType::Null), Some(err) => Err(FastExcelErrorKind::CalamineCellError(err.to_owned()).into()), None => Err(FastExcelErrorKind::Internal(format!( "cell is an error but get_error returned None: {cell:?}"