pola-rs/polars · error · ValueError
the `table_name` parameter is not supported by the…
Error message
the `table_name` parameter is not supported by the 'xlsx2csv' engine
What it means
When reading Excel spreadsheets via `pl.read_excel`, the `table_name` parameter (which selects a named Excel table) is only implemented for the 'calamine' engine. The `_read_spreadsheet_xlsx2csv` helper raises this ValueError up front because the xlsx2csv library cannot look up named tables; passing a table name there would otherwise be silently ignored.
Solutions
- Use the default 'calamine' engine, which supports `table_name`: `pl.read_excel(source, table_name='mytable')` or explicitly `engine='calamine'`.
- If xlsx2csv must stay, drop `table_name` and select the sheet/region manually via `sheet_name` plus `read_options` (e.g. skip rows) or slice the resulting DataFrame.
- Convert the named table's range into an explicit sheet+range read, or read the whole sheet and filter afterward.
- Pin/upgrade polars so the docs and supported engines match your usage.
Example fix
// before
pl.read_excel("data.xlsx", table_name="SalesTable", engine="xlsx2csv")
// after
pl.read_excel("data.xlsx", table_name="SalesTable") # default calamine engine Defensive patterns
Strategy: validation
Validate before calling
if table_name is not None and engine == "xlsx2csv":
raise ValueError("use engine='calamine' with table_name") Type guard
def supports_table_name(engine: str) -> bool:
return engine in {"calamine"} Prevention
- Only pass table_name with the calamine engine
- Omit engine to use the polars default
- Keep read_excel calls and engine choices documented together
When it happens
Trigger: Calling `pl.read_excel(..., table_name='mytable', engine='xlsx2csv')` (or with engine inferred/resolved to 'xlsx2csv') while supplying a non-None `table_name`. The check fires in `_read_spreadsheet_xlsx2csv` before any file is parsed.
Common situations: Following documentation or blog examples written for the default calamine engine but running with `engine='xlsx2csv'` explicitly set; inheriting an engine choice from a wrapper or older config; sharing code across environments where the default engine differs.
Related errors
- cannot specify both `columns` and `read_options["columns"]`
- cannot specify both `columns` and…
- cannot specify both `infer_schema_length` and…
- cannot specify both `sheet_name
- file must be opened in binary mode
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/68be2426a27f7d4d.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/spreadsheet/functions.py:1317
return df
def _read_spreadsheet_xlsx2csv(
parser: Any,
*,
sheet_name: str | None,
read_options: dict[str, Any],
schema_overrides: SchemaDict | None,
columns: Sequence[int] | Sequence[str] | None,
table_name: str | None = None,
drop_empty_rows: bool,
drop_empty_cols: bool,
raise_if_empty: bool,
) -> pl.DataFrame:
"""Use the 'xlsx2csv' library to read data from the given worksheet."""
if table_name:
msg = "the `table_name` parameter is not supported by the 'xlsx2csv' engine"
raise ValueError(msg)
csv_buffer = StringIO()
with warnings.catch_warnings():
# xlsx2csv version 0.8.4 throws a DeprecationWarning in Python 3.13
# https://github.com/dilshod/xlsx2csv/pull/287
warnings.filterwarnings("ignore", category=DeprecationWarning)
parser.convert(outfile=csv_buffer, sheetname=sheet_name)
read_options.setdefault("truncate_ragged_lines", True)
if columns:
read_options["columns"] = columns
cast_to_boolean = []
if schema_overrides:
for col, dtype in schema_overrides.items():
if dtype == Boolean:
schema_overrides[col] = UInt8 # type: ignore[index]
cast_to_boolean.append(F.col(col).cast(Boolean))View on GitHub (pinned to fe841f959e)