pola-rs/polars · error · ModuleUpgradeRequiredError

a more recent version of `fastexcel` is required for…

Error message

a more recent version of `fastexcel` is required for 'schema_sample_rows' (>= 0.9; found {original_version})

What it means

The `schema_sample_rows` read option for the calamine engine requires fastexcel >= 0.9. If an older fastexcel is installed and that key is present in read_options, polars raises ModuleUpgradeRequiredError with the required and installed versions. This gate exists because older fastexcel lacks the schema-sampling API.

Solutions

  1. Upgrade fastexcel: pip install -U 'fastexcel>=0.9'.
  2. Pin fastexcel>=0.9 in project dependencies.
  3. Drop schema_sample_rows from read_options and instead pass explicit `schema_overrides`/dtypes for the affected columns.

Example fix

// before
pl.read_excel('f.xlsx', engine='calamine', read_options={'schema_sample_rows': 500})
// after
# pip install -U 'fastexcel>=0.9'
pl.read_excel('f.xlsx', engine='calamine', read_options={'schema_sample_rows': 500})
Defensive patterns

Strategy: validation

Validate before calling

from importlib.metadata import version
from packaging.version import Version
if Version(version('fastexcel')) < Version('0.9'):
    raise RuntimeError('fastexcel>=0.9 required for schema_sample_rows')

Try / catch

try:
    df = pl.read_excel(path, engine='calamine', read_options={'schema_sample_rows': n})
except ModuleUpgradeRequiredError:
    df = pl.read_excel(path, engine='calamine', schema_overrides=explicit_dtypes)

Prevention

When it happens

Trigger: `pl.read_excel(..., engine='calamine', read_options={'schema_sample_rows': 100})` with fastexcel < 0.9 installed.

Common situations: Old fastexcel in a locked environment; copied snippets using schema_sample_rows to fix type inference; CI images with stale dependencies.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

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

    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:
    # if we have 'schema_overrides' and a more recent version of `fastexcel`
    # we can pass translated dtypes to the engine to refine the initial parse
    fastexcel = import_optional("fastexcel")
    fastexcel_version = parse_version(original_version := fastexcel.__version__)

    if fastexcel_version < (0, 9) and "schema_sample_rows" in read_options:
        msg = f"a more recent version of `fastexcel` is required for 'schema_sample_rows' (>= 0.9; found {original_version})"
        raise ModuleUpgradeRequiredError(msg)
    if fastexcel_version < (0, 10, 2) and "use_columns" in read_options:
        msg = f"a more recent version of `fastexcel` is required for 'use_columns' (>= 0.10.2; found {original_version})"
        raise ModuleUpgradeRequiredError(msg)
    if table_name and fastexcel_version < (0, 12):
        msg = f"a more recent version of `fastexcel` is required for 'table_name' (>= 0.12.0; found {original_version})"
        raise ValueError(msg)

    if columns:
        if not isinstance(columns, list):
            columns = list(columns)  # type: ignore[assignment]
        read_options["use_columns"] = columns

    schema_overrides = schema_overrides or {}
    if read_options.get("schema_sample_rows") == 0:
        # ref: https://github.com/ToucanToco/fastexcel/issues/236
        del read_options["schema_sample_rows"]
        read_options["dtypes"] = (
            "string"
            if fastexcel_version >= (0, 12, 1)
            else dict.fromkeys(range(16384), "string")
        )

View on GitHub (pinned to fe841f959e)