{"record":{"id":"01503a5877f486ed","repo":"pola-rs/polars","slug":"no-data-found-in-the-given-workbook-s-and-sheet-s","errorCode":null,"errorMessage":"no data found in the given workbook(s) and sheet(s)","messagePattern":"no data found in the given workbook\\(s\\) and sheet\\(s\\)","errorType":"exception","errorClass":"NoDataError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/functions.py","lineNumber":99,"sourceCode":"                src = str(src)\n            sources.append(src)\n\n    return sources, read_multiple_workbooks\n\n\ndef _standardize_duplicates(s: str) -> str:\n    \"\"\"Standardize columns with '_duplicated_n' names.\"\"\"\n    return re.sub(r\"_duplicated_(\\d+)\", repl=r\"\\1\", string=s)\n\n\ndef _unpack_read_results(\n    frames: list[pl.DataFrame] | list[dict[str, pl.DataFrame]],\n    *,\n    read_multiple_workbooks: bool,\n) -> Any:\n    if not frames:\n        msg = \"no data found in the given workbook(s) and sheet(s)\"\n        raise NoDataError(msg)\n\n    if not read_multiple_workbooks:\n        # one sheet from one workbook\n        return frames[0]\n\n    if isinstance(frames[0], pl.DataFrame):\n        # one sheet from multiple workbooks\n        return concat(frames, how=\"vertical_relaxed\")  # type: ignore[type-var]\n    else:\n        # multiple sheets from multiple workbooks\n        sheet_frames = defaultdict(list)\n        for res in frames:\n            for sheet, df in res.items():  # type: ignore[union-attr]\n                sheet_frames[sheet].append(df)\n        return {k: concat(v, how=\"vertical_relaxed\") for k, v in sheet_frames.items()}\n\n\n@overload","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/spreadsheet/functions.py#L81-L117","documentation":"polars.exceptions.NoDataError raised by _unpack_read_results after reading Excel sources: the read completed but produced zero DataFrames. This happens when every selected sheet parsed to nothing — e.g. sheets whose rows were all dropped by drop_empty_rows/drop_empty_cols — so there is no frame to return or concatenate.","triggerScenarios":"pl.read_excel('empty.xlsx') where the sheet has only blank rows and drop_empty_rows=True (default); reading multiple workbooks via glob where every matched file is empty; sheet combinations that select only blank sheets.","commonSituations":"Scheduled jobs reading a periodically-generated report that is occasionally empty; templates with header-only or whitespace-only sheets; glob patterns matching both data files and blank placeholder files.","solutions":["Inspect the workbook and confirm the target sheet actually contains data (check it in Excel/another reader).","Handle the empty case explicitly: wrap in try/except NoDataError and substitute an explicit empty schema or skip processing, rather than letting the exception kill the job.","Tighten glob patterns or sheet selection (sheet_name/sheet_id) so blank placeholder sheets are not read.","If blank-looking rows matter, revisit drop_empty_rows=False / raise_if_empty-style handling."],"exampleFix":"# before\ndf = pl.read_excel('report.xlsx')  # NoDataError when sheet is blank\n\n# after\ntry:\n    df = pl.read_excel('report.xlsx')\nexcept pl.exceptions.NoDataError:\n    df = pl.DataFrame(schema={'date': pl.Date, 'amount': pl.Float64})  # explicit empty result","handlingStrategy":"try-catch","validationCode":"# Optional pre-check that the target sheet has any non-empty cells (needs openpyxl):\nfrom openpyxl import load_workbook\nwb = load_workbook(path, read_only=True)\nhas_any = any(cell.value is not None for row in wb[sheet].iter_rows() for cell in row)\nif not has_any:\n    df = pl.DataFrame(schema=expected_schema)  # skip the read\nelse:\n    df = pl.read_excel(path, sheet_name=sheet)","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_excel(path, sheet_name=sheet)\nexcept pl.exceptions.NoDataError:\n    df = pl.DataFrame(schema=expected_schema)  # explicit, typed empty result\n    log.warning('workbook %s sheet %s contained no data', path, sheet)","preventionTips":["Treat empty workbooks as an expected input state for scheduled/ETL reads, not an exception.","Standardize an empty-frame fallback with an explicit schema so downstream code stays typed.","Tighten glob patterns and sheet selection so blank template sheets are never selected."],"tags":["excel","spreadsheet","read-excel","empty-data","io"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}