pola-rs/polars · error · ParameterCollisionError

cannot specify both `infer_schema_length` and…

Error message

cannot specify both `infer_schema_length` and `read_options["infer_schema_length"]`

What it means

For the xlsx2csv engine, `read_excel` injects the top-level `infer_schema_length` into `read_options["infer_schema_length"]`. If the caller set `infer_schema_length` inside `read_options` while also passing a non-default top-level `infer_schema_length`, both compete and Polars raises `ParameterCollisionError`.

Solutions

  1. Remove `infer_schema_length` from `read_options` and use the top-level parameter
  2. Or drop the top-level `infer_schema_length` and configure it only via read_options

Example fix

// before
pl.read_excel(f, engine='xlsx2csv', infer_schema_length=100, read_options={'infer_schema_length': 0})
// after
pl.read_excel(f, engine='xlsx2csv', read_options={'infer_schema_length': 0})
Defensive patterns

Strategy: validation

Validate before calling

assert not ('infer_schema_length' in read_options and infer_schema_length is not None), 'infer_schema_length conflict'

Try / catch

from polars.exceptions import ParameterCollisionError
try:
    pl.read_excel(f, engine='xlsx2csv', infer_schema_length=n, read_options=ro)
except ParameterCollisionError:
    ro.pop('infer_schema_length', None)
    df = pl.read_excel(f, engine='xlsx2csv', infer_schema_length=n, read_options=ro)

Prevention

When it happens

Trigger: `pl.read_excel(..., engine='xlsx2csv', infer_schema_length=100, read_options={'infer_schema_length': 0})` — any non-None/non-default top-level value combined with the key in read_options.

Common situations: Tuning schema inference in two places after upgrading; spreading a config dict into read_options that already contains infer_schema_length.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/009125c028309ae3. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/spreadsheet/functions.py:768

            infer_schema_length != N_INFER_DEFAULT
        ):
            msg = 'cannot specify both `infer_schema_length` and `read_options["schema_sample_rows"]`'
            raise ParameterCollisionError(msg)

        read_options["schema_sample_rows"] = infer_schema_length
        if has_header is False and "header_row" not in read_options:
            read_options["header_row"] = None

    elif engine == "xlsx2csv":
        if ("columns" in read_options) and columns:
            msg = 'cannot specify both `columns` and `read_options["columns"]`'
            raise ParameterCollisionError(msg)
        elif (
            "has_header" in read_options
            and read_options["has_header"] is not has_header
        ):
            msg = 'the values of `has_header` and `read_options["has_header"]` are not compatible'
            raise ParameterCollisionError(msg)
        elif ("infer_schema_length" in read_options) and (
            infer_schema_length != N_INFER_DEFAULT
        ):
            msg = 'cannot specify both `infer_schema_length` and `read_options["infer_schema_length"]`'
            raise ParameterCollisionError(msg)

        read_options["infer_schema_length"] = infer_schema_length
        if "has_header" not in read_options:
            read_options["has_header"] = has_header
    else:
        read_options["infer_schema_length"] = infer_schema_length
        read_options["has_header"] = has_header

    return read_options


def _get_sheet_names(
    sheet_id: int | Sequence[int] | None,

View on GitHub (pinned to fe841f959e)