pola-rs/polars · error · ValueError
no matching sheets found when `sheet_
Error message
no matching sheets found when `sheet_{param}` is {value!r} What it means
_read_spreadsheet raises ValueError when no parsed sheet matches the requested sheet_id or sheet_name. The message dynamically names which parameter was used (`sheet_id` or `sheet_name`) and echoes its value.
Solutions
- List available sheets first (pl.read_excel(src, sheet_id=None) returns a dict keyed by sheet name) and pick the correct name/id.
- Fix the sheet_name spelling/case or the sheet_id number.
- Pass sheet_id=None and select the frame from the returned dict instead of guessing the id.
Example fix
// before
pl.read_excel('wb.xlsx', sheet_name='Sales 2024') # actual: 'sales 2024'
// after
sheets = pl.read_excel('wb.xlsx') # dict of all sheets
frame = sheets['sales 2024'] Defensive patterns
Strategy: validation
Validate before calling
available = pl.read_excel(src) # dict of all sheets
assert sheet_name in available, f'{sheet_name!r} not in {list(available)}' Try / catch
try:
df = pl.read_excel(src, sheet_name=name)
except ValueError as e:
if 'no matching sheets' in str(e):
sheets = pl.read_excel(src)
raise KeyError(f'{name!r} not found; have {list(sheets)}') from None
raise Prevention
- Discover sheet names/ids dynamically instead of hardcoding
- Normalize case/whitespace of sheet names
- Re-verify ids after workbook edits
When it happens
Trigger: pl.read_excel(src, sheet_name='Shet1') (typo), sheet_id=5 on a 3-sheet workbook, or name/id given with different case/whitespace than the actual sheet names.
Common situations: Renamed sheets, case-sensitive matching, trailing spaces in sheet names, or hardcoded sheet ids that shifted after the workbook was edited.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- cannot create a second
- cannot specify both `columns` and `read_options["columns"]`
- cannot specify both `columns` and…
- cannot specify both `infer_schema_length` and…
- cannot specify both `infer_schema_length` and…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/0f6de73c4ce00c93.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/spreadsheet/functions.py:718
sheet_name=name,
schema_overrides=schema_overrides,
read_options=read_options,
raise_if_empty=raise_if_empty,
columns=columns,
table_name=table_name,
drop_empty_rows=drop_empty_rows,
drop_empty_cols=drop_empty_cols,
)
for name in sheet_names
}
finally:
if hasattr(parser, "close"):
parser.close()
if not parsed_sheets:
param, value = ("id", sheet_id) if sheet_name is None else ("name", sheet_name)
msg = f"no matching sheets found when `sheet_{param}` is {value!r}"
raise ValueError(msg)
if include_file_paths:
workbook = source if isinstance(source, str) else "in-mem"
parsed_sheets = {
name: frame.with_columns(F.lit(workbook).alias(include_file_paths))
for name, frame in parsed_sheets.items()
}
if return_multiple_sheets:
return parsed_sheets
return next(iter(parsed_sheets.values()))
def _get_read_options(
read_options: dict[str, Any] | None,
*,
engine: ExcelSpreadsheetEngine,
columns: Sequence[int] | Sequence[str] | None,
infer_schema_length: int | None,View on GitHub (pinned to fe841f959e)