pola-rs/polars · error · ValueError

invalid `scaling_mode

Error message

invalid `scaling_mode` {scaling_mode!r}

What it means

The remote engine's scaling configuration accepts only a fixed set of scaling_mode values (_SCALING_MODES, e.g. 'single-node', 'autoscaling'). Passing anything else in the RemoteEngine/EngineRemote constructor raises ValueError.

Solutions

  1. Use an accepted scaling_mode such as 'single-node' or 'autoscaling'.
  2. Omit scaling_mode to use the default.
  3. Check membership against the engine module's _SCALING_MODES before constructing.

Example fix

// before
engine = RemoteEngine(scaling_mode='auto')

// after
engine = RemoteEngine(scaling_mode='autoscaling')
Defensive patterns

Strategy: validation

Validate before calling

if scaling_mode is not None and scaling_mode not in ('single-node', 'autoscaling'):
    raise ValueError(f'bad scaling_mode {scaling_mode!r}')

Type guard

def is_valid_scaling_mode(v: object) -> bool:
    return v in ('single-node', 'autoscaling')

Try / catch

try:
    engine = RemoteEngine(scaling_mode=scaling_mode)
except ValueError:
    engine = RemoteEngine()

Prevention

When it happens

Trigger: Constructing the remote engine as e.g. EngineRemote(scaling_mode='auto') or EngineRemote(scaling_mode='cluster'), or loading scaling_mode from config with a typo.

Common situations: Guessing the scaling mode name instead of consulting polars-cloud docs; reusing values from other orchestrators ('elastic', 'fixed'); YAML/JSON config drift.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/lazyframe/engine_remote.py:128

    labels: list[str] | None
    """Labels attached to the query."""
    config: Mapping[str, Any]
    """Additional options forwarded to the distributed planner."""

    def __init__(
        self,
        context: pc.ClientContext | None = None,
        *,
        scaling_mode: ScalingMode = "auto",
        engine: EngineTypeName = "auto",
        plan_type: PlanTypePreference = "dot",
        n_retries: int = 0,
        labels: list[str] | str | None = None,
        **kwargs: Any,
    ) -> None:
        if scaling_mode not in _SCALING_MODES:
            msg = f"invalid `scaling_mode` {scaling_mode!r}"
            raise ValueError(msg)
        if engine not in _WORKER_ENGINE_NAMES:
            msg = f"Invalid engine argument {engine=}"
            raise ValueError(msg)
        if scaling_mode == "single-node" and kwargs:
            msg = (
                f"distributed options {sorted(kwargs)!r} are not supported with "
                "`scaling_mode='single-node'`"
            )
            raise ValueError(msg)

        # fail here rather than deep inside a sink
        import_optional(
            "polars_cloud",
            err_prefix="remote engine requested, but required package",
            install_message="Please install using the command `pip install polars-cloud`",
        )

        self.context = context

View on GitHub (pinned to fe841f959e)