pola-rs/polars · error · ValueError

expected Series in 'arg_where' if 'eager=True', got

Error message

expected Series in 'arg_where' if 'eager=True', got {type(condition).__name__!r}

What it means

`pl.arg_where(condition, eager=True)` requires `condition` to be a boolean `pl.Series`, since eager mode evaluates immediately against a concrete mask. Any other type (list, Expr, string) raises ValueError including the offending type name.

Solutions

  1. Convert the input: `pl.Series([True, False, True])`
  2. Drop `eager=True` and use `df.select(pl.arg_where(pl.col("mask")))` for expr inputs
  3. Ensure the Series is boolean dtype

Example fix

// before
pl.arg_where([True, False], eager=True)
// after
pl.arg_where(pl.Series([True, False]), eager=True)
Defensive patterns

Strategy: type-guard

Validate before calling

def arg_where_eager(cond):
    if not isinstance(cond, pl.Series):
        cond = pl.Series(cond)
    return pl.arg_where(cond, eager=True)

Type guard

def arg_where_eager_ok(c): return isinstance(c, pl.Series)

Try / catch

try:
    return pl.arg_where(cond, eager=True)
except ValueError:
    return pl.arg_where(pl.Series(cond), eager=True)

Prevention

When it happens

Trigger: Calling `pl.arg_where([True, False, True], eager=True)` with a Python list, or passing an Expr/string with `eager=True`.

Common situations: Passing plain Python lists/arrays instead of Series; mixing lazy expression API with eager flag.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/functions/lazy.py:2312

    >>> df.select(
    ...     [
    ...         pl.arg_where(pl.col("a") % 2 == 0),
    ...     ]
    ... ).to_series()
    shape: (2,)
    Series: 'a' [u32]
    [
        1
        3
    ]
    """
    if eager:
        if not isinstance(condition, pl.Series):
            msg = (
                "expected Series in 'arg_where' if 'eager=True', got"
                f" {type(condition).__name__!r}"
            )
            raise ValueError(msg)
        return condition.to_frame().select(arg_where(F.col(condition.name))).to_series()
    else:
        condition_pyexpr = parse_into_expression(condition)
        return wrap_expr(plr.arg_where(condition_pyexpr))


@overload
def coalesce(
    exprs: IntoExpr | Iterable[IntoExpr],
    *more_exprs: IntoExpr,
    eager: Literal[False] = ...,
) -> Expr: ...


@overload
def coalesce(
    exprs: IntoExpr | Iterable[IntoExpr],
    *more_exprs: IntoExpr,

View on GitHub (pinned to fe841f959e)