{"record":{"id":"905b03a0740588bd","repo":"pola-rs/polars","slug":"no-named-tables-found-in-sheet-sheet-name-r-loo","errorCode":null,"errorMessage":"no named tables found in sheet {sheet_name!r} (looking for {table_name!r})","messagePattern":"no named tables found in sheet (.+?) \\(looking for (.+?)\\)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/spreadsheet/functions.py","lineNumber":1219,"sourceCode":"    has_header = read_options.pop(\"has_header\", True)\n    schema_overrides = schema_overrides or {}\n    no_inference = infer_schema_length == 0\n    header: list[str | None] = []\n\n    if table_name and not sheet_name:\n        ws, sheet_name, n_tables = None, None, 0\n        for sheet in parser.worksheets:\n            n_tables += 1\n            if table_name in sheet.tables:\n                ws, sheet_name = sheet, sheet.title\n                break\n        if ws is None:\n            msg = (\n                f\"table named {table_name!r} not found in sheet {sheet_name!r}\"\n                if n_tables\n                else f\"no named tables found in sheet {sheet_name!r} (looking for {table_name!r})\"\n            )\n            raise RuntimeError(msg)\n    else:\n        ws = parser[sheet_name]\n\n    # prefer detection of actual table objects; otherwise read\n    # data in the used worksheet range, dropping null columns\n    if tables := getattr(ws, \"tables\", None):\n        table = tables[table_name] if table_name else next(iter(tables.values()))\n        rows = list(ws[table.ref])\n        if not rows:\n            return _empty_frame(raise_if_empty)\n        if has_header:\n            header.extend(cell.value for cell in rows.pop(0))\n        else:\n            header.extend(f\"column_{n}\" for n in range(1, len(rows[0]) + 1))\n        if table.totalsRowCount:\n            rows = rows[: -table.totalsRowCount]\n        rows_iter = rows\n    elif table_name:","sourceCodeStart":1201,"sourceCodeEnd":1237,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/spreadsheet/functions.py#L1201-L1237","documentation":"The else-branch of the same raise in _read_spreadsheet_openpyxl as error 436: it fires only when n_tables == 0, i.e. the loop over parser.worksheets never ran — the workbook contains zero worksheets. Since sheet_name stays None, the message renders as \"no named tables found in sheet None (looking for 'X')\". A workbook with no sheets at all is unusual (Excel itself always keeps one) and typically indicates a corrupt, empty, or mis-generated xlsx.","triggerScenarios":"pl.read_excel(src, table_name='X', engine='openpyxl') on an xlsx whose workbook.xml declares no sheets; a truncated download (HTTP response cut short but parseable); a workbook skeleton written by a broken generator.","commonSituations":"Interrupted file transfers; test fixtures that write empty workbooks; files produced by failing upstream jobs that still emit a zip container.","solutions":["Open the file in Excel/LibreOffice — if it will not open, the file is corrupt: re-download or regenerate it","Verify with openpyxl first: wb = openpyxl.load_workbook(path, read_only=True); assert wb.worksheets","Guard ingestion pipelines with a file-integrity check (size, zip validity) before parsing"],"exampleFix":"# before\npl.read_excel(src, table_name='Sales', engine='openpyxl')\n\n# after (validate the workbook has sheets first)\nimport openpyxl\nwb = openpyxl.load_workbook(src, read_only=True)\nif not wb.worksheets:\n    raise ValueError(f'{src}: workbook has no worksheets (corrupt or empty file)')\npl.read_excel(src, table_name='Sales', engine='openpyxl')","handlingStrategy":"validation","validationCode":"import openpyxl, zipfile\n\ndef workbook_is_readable(path) -> bool:\n    if not zipfile.is_zipfile(path):\n        return False\n    with openpyxl.load_workbook(path, read_only=True) as wb:\n        return bool(wb.worksheets)  # zero worksheets -> this error (message shows 'sheet None')\n\nif not workbook_is_readable(src):\n    raise ValueError(f'{src}: corrupt/empty workbook — regenerate or re-download it')\ndf = pl.read_excel(src, table_name=tbl, engine='openpyxl')","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_excel(src, table_name=tbl, engine='openpyxl')\nexcept RuntimeError as e:\n    if 'no named tables found' in str(e) and 'sheet None' in str(e):\n        raise ValueError(f'{src}: workbook has no worksheets (corrupt file)') from e\n    raise","preventionTips":["Validate downloads (zip integrity + non-zero size + at least one worksheet) before parsing","This branch means the workbook literally has zero sheets — treat it as file corruption, not a lookup miss","Add retry-from-source logic for fetched workbooks at the download layer, not around read_excel"],"tags":["polars","excel","openpyxl","table","corrupt-file","empty-workbook"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}