{"record":{"id":"5d2ca7bf0533fae4","repo":"pola-rs/polars","slug":"empty-excel-sheet-n-nif-you-want-to-read-this-as-a","errorCode":null,"errorMessage":"empty Excel sheet\\n\\nIf you want to read this as an empty DataFrame, set `raise_if_empty=False`.","messagePattern":"empty Excel sheet\\\\n\\\\nIf you want to read this as an empty DataFrame, set `raise_if_empty=False`\\.","errorType":"exception","errorClass":"NoDataError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/functions.py","lineNumber":1013,"sourceCode":"                ):\n                    null_cols.append(col_name)\n        if null_cols:\n            df = df.drop(*null_cols)\n\n    if df.height == df.width == 0:\n        return _empty_frame(raise_if_empty)\n    if drop_empty_rows:\n        return df.filter(~F.all_horizontal(F.all().is_null()))\n    return df\n\n\ndef _empty_frame(raise_if_empty: bool) -> pl.DataFrame:  # noqa: FBT001\n    if raise_if_empty:\n        msg = (\n            \"empty Excel sheet\"\n            \"\\n\\nIf you want to read this as an empty DataFrame, set `raise_if_empty=False`.\"\n        )\n        raise NoDataError(msg)\n    return pl.DataFrame()\n\n\ndef _reorder_columns(\n    df: pl.DataFrame, columns: Sequence[int] | Sequence[str] | None\n) -> pl.DataFrame:\n    if columns:\n        from polars.selectors import by_index, by_name\n\n        cols = (\n            by_index(*columns)\n            if is_non_empty_sequence_of(columns, int)\n            else by_name(*columns)\n        )\n        df = df.select(cols)\n    return df\n\n","sourceCodeStart":995,"sourceCodeEnd":1031,"githubUrl":"https://github.com/pola-rs/polars/blob/5d8ebabf11caea54a5c29178a64a058762f49766/py-polars/src/polars/io/spreadsheet/functions.py#L995-L1031","documentation":"NoDataError raised by _empty_frame after the Excel reader produced a zero-row, zero-column result. It means the sheet exists but contains no data; the message points at raise_if_empty=False as the way to accept an empty DataFrame instead.","triggerScenarios":"Thrown at py-polars/src/polars/io/spreadsheet/functions.py:1010 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set raise_if_empty=False to read the empty sheet as an empty DataFrame, or point to a non-empty sheet."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5d8ebabf11caea54a5c29178a64a058762f49766","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}