pola-rs/polars · error

invalid engine

Error message

invalid engine

What it means

Config.set_engine_affinity validates the engine name against SUPPORTED_ENGINE_NAMES (plus None to reset) before storing POLARS_ENGINE_AFFINITY. Any other value raises a plain ValueError with the message 'invalid engine'. This config pins which execution engine (e.g. 'in-memory', 'streaming') Polars uses.

Solutions

  1. Use a supported name, e.g. pl.Config.set_engine_affinity('in-memory') or 'streaming'.
  2. Pass None to clear the override and use the default engine selection.
  3. Check polars.exceptions / docs for SUPPORTED_ENGINE_NAMES in your installed version, as names change across releases.

Example fix

// before
pl.Config.set_engine_affinity("old-streaming")
// after
pl.Config.set_engine_affinity("streaming")
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {"in-memory", "streaming"}  # match SUPPORTED_ENGINE_NAMES for your version
if engine is not None and engine not in SUPPORTED:
    raise ValueError(f"engine must be one of {SUPPORTED} or None")
pl.Config.set_engine_affinity(engine)

Type guard

def is_valid_engine(v) -> bool:
    return v is None or (isinstance(v, str) and v in {"in-memory", "streaming"})

Try / catch

try:
    pl.Config.set_engine_affinity(engine)
except ValueError:
    logging.warning("unknown engine %r; using default", engine)
    pl.Config.set_engine_affinity(None)

Prevention

When it happens

Trigger: pl.Config.set_engine_affinity('gpu'), 'lazy', 'old-streaming', or any misspelled engine name; also via Config.enable_monitoring if it forwards an invalid engine.

Common situations: Using engine names from other libraries (e.g. dask 'gpu' variants) or from older Polars versions where the streaming engine had a different name.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/config.py:1606

        >>> pl.Config.set_engine_affinity(
        ...     pl.GPUEngine(device=1, raise_on_fail=True)
        ... )  # doctest: +SKIP

        Raises
        ------
        ValueError: if engine is not recognised.
        """
        if isinstance(engine, Engine):
            # Object affinities are Python-only; clear the named affinity.
            os.environ.pop("POLARS_ENGINE_AFFINITY", None)
            set_engine_affinity_override(engine)
            plr.config_reload_env_var("POLARS_ENGINE_AFFINITY")
            return cls

        if engine not in {*SUPPORTED_ENGINE_NAMES, None}:
            msg = "invalid engine"
            raise ValueError(msg)
        if engine is None:
            os.environ.pop("POLARS_ENGINE_AFFINITY", None)
        else:
            os.environ["POLARS_ENGINE_AFFINITY"] = engine
        set_engine_affinity_override(None)
        plr.config_reload_env_var("POLARS_ENGINE_AFFINITY")

        return cls

    @classmethod
    def enable_monitoring(
        cls,
        active: bool | None = True,
        *,
        workspace: str | None = None,
        organization: str | None = None,
    ) -> type[Config]:
        """

View on GitHub (pinned to fe841f959e)