Skip to content

Consider #NUM! errors values as None #320

Closed
@sphuber

Description

@sphuber

Consider the following example file:
fixture-invalid-cell-value-num.xlsx
image
This currently fails with:

In [46]: r = fastexcel.read_excel("tmp/ex_broken_minimal.xlsx")

In [47]: r.load_sheet(0)
---------------------------------------------------------------------------
CalamineCellError                         Traceback (most recent call last)
Cell In[47], line 1
----> 1 r.load_sheet(0)

File /usr/local/lib/python3.9/site-packages/fastexcel/__init__.py:256, in ExcelReader.load_sheet(self, idx_or_name, header_row, column_names, skip_rows, n_rows, schema_sample_rows, dtype_coercion, use_columns, dtypes)
    205 def load_sheet(
    206     self,
    207     idx_or_name: int | str,
   (...)
    216     dtypes: DType | DTypeMap | None = None,
    217 ) -> ExcelSheet:
    218     """Loads a sheet lazily by index or name.
    219 
    220     :param idx_or_name: The index (starting at 0) or the name of the sheet to load.
   (...)
    253                    or dict of dtypes with keys as column indices or names.
    254     """
    255     return ExcelSheet(
--> 256         self._reader.load_sheet(
    257             idx_or_name=idx_or_name,
    258             header_row=header_row,
    259             column_names=column_names,
    260             skip_rows=skip_rows,
    261             n_rows=n_rows,
    262             schema_sample_rows=schema_sample_rows,
    263             dtype_coercion=dtype_coercion,
    264             use_columns=use_columns,
    265             dtypes=dtypes,
    266             eager=False,
    267         )
    268     )

CalamineCellError: calamine cell error: #NUM!
Context:
    0: could not determine dtype for column 8

The #NUM! value is parsed by calamine just fine, it just raises CellErrorType::Num

This was fixed for #N/A errors in #180 . We could add the same handling for CellErrorType::Num perhaps?

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