pola-rs/polars · error · TypeError

collect() got an unexpected keyword argument

Error message

collect() got an unexpected keyword argument '{k}'

What it means

The engine-based collect() validates its keyword arguments and raises TypeError for any kwarg it does not recognize (except the internal 'post_opt_callback'). This usually means an argument valid for an older collect() signature (or another method) was passed here.

Solutions

  1. Remove the unknown kwarg and consult the current collect() signature
  2. Migrate `streaming=True` to `engine='streaming'`
  3. Pass plan optimizations via the `optimizations=` parameter instead of individual flags

Example fix

// before
df = lf.collect(streaming=True)

// after
df = lf.collect(engine='streaming')
Defensive patterns

Strategy: validation

Validate before calling

import inspect
valid = inspect.signature(lf.collect).parameters
unexpected = set(kwargs) - set(valid)
assert not unexpected, f"unexpected kwargs: {unexpected}"

Try / catch

try:
    df = lf.collect(**kwargs)
except TypeError as e:
    if "unexpected keyword argument" in str(e):
        kwargs.pop('streaming', None)
        df = lf.collect(engine='streaming', **kwargs)
    else:
        raise

Prevention

When it happens

Trigger: `lf.collect(streaming=True)` on new polars, passing old flags like `type_coercion=False` directly, or forwarding wrapper **kwargs into collect().

Common situations: Upgrading polars where parameters moved into `engine`/`optimizations`; wrappers that blindly pass **kwargs; copying collect_all or scan options into collect.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/lazyframe/frame.py:2220

        ...     engine=pl.GPUEngine(device=1)
        ... )  # doctest: +SKIP
        shape: (3, 3)
        ┌─────┬─────┬─────┐
        │ a   ┆ b   ┆ c   │
        │ --- ┆ --- ┆ --- │
        │ str ┆ i64 ┆ i64 │
        ╞═════╪═════╪═════╡
        │ b   ┆ 11  ┆ 10  │
        │ a   ┆ 4   ┆ 10  │
        │ c   ┆ 6   ┆ 1   │
        └─────┴─────┴─────┘
        """
        for k in _kwargs:
            if k not in (  # except "private" kwargs
                "post_opt_callback",
            ):
                error_msg = f"collect() got an unexpected keyword argument '{k}'"
                raise TypeError(error_msg)

        engine_ = _select_engine(engine)
        post_opt_callback = _kwargs.get("post_opt_callback")

        return engine_.collect(
            self,
            optimizations=optimizations,
            background=background,
            post_opt_callback=post_opt_callback,
        )

    @overload
    def collect_async(
        self,
        *,
        gevent: Literal[True],
        engine: EngineType = "auto",
        optimizations: QueryOptFlags = DEFAULT_QUERY_OPT_FLAGS,

View on GitHub (pinned to fe841f959e)