pola-rs/polars · error · ValueError

expected at least one Series in 'cov' inputs if 'eager=True'

Error message

expected at least one Series in 'cov' inputs if 'eager=True'

What it means

`pl.cov(a, b, eager=True)` requires at least one input to be a `pl.Series` so it can construct the DataFrame used for eager evaluation; if neither is a Series it raises ValueError. String column names or expressions are only valid in lazy mode.

Solutions

  1. Pass at least one `pl.Series`, e.g. `pl.cov(df["a"], df["b"], eager=True)`
  2. Use `df.select(pl.cov("a", "b"))` for lazy/expr inputs
  3. Remove `eager=True` if lazy evaluation was intended

Example fix

// before
pl.cov("a", "b", eager=True)
// after
df.select(pl.cov("a", "b"))
Defensive patterns

Strategy: type-guard

Validate before calling

if eager and not (isinstance(a, pl.Series) or isinstance(b, pl.Series)):
    raise TypeError("cov(eager=True) needs at least one pl.Series")

Type guard

def cov_eager_ok(a, b): return isinstance(a, pl.Series) or isinstance(b, pl.Series)

Try / catch

try:
    return pl.cov(a, b, eager=True)
except ValueError:
    return df.select(pl.cov(a, b)).to_series()

Prevention

When it happens

Trigger: Calling `pl.cov("a", "b", eager=True)` with two string column names or two Exprs.

Common situations: Mixing lazy and eager API conventions; converting code from `df.select(pl.cov(...))` to eager form without converting inputs.

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/0f02b59ef59a457e. Report an issue: GitHub.

Appendix: source

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

    ╞═════╪═════╡
    │ 3.0 ┆ 6.0 │
    └─────┴─────┘

    Eager evaluation:

    >>> s1 = pl.Series("a", [1, 8, 3])
    >>> s2 = pl.Series("b", [4, 5, 2])
    >>> pl.cov(s1, s2, eager=True)
    shape: (1,)
    Series: 'a' [f64]
    [
        3.0
    ]
    """
    if eager:
        if not (isinstance(a, pl.Series) or isinstance(b, pl.Series)):
            msg = "expected at least one Series in 'cov' inputs if 'eager=True'"
            raise ValueError(msg)

        frame = pl.DataFrame([e for e in (a, b) if isinstance(e, pl.Series)])
        exprs = ((e.name if isinstance(e, pl.Series) else e) for e in (a, b))
        return frame.select(cov(*exprs, eager=False, ddof=ddof)).to_series()
    else:
        a_pyexpr = parse_into_expression(a)
        b_pyexpr = parse_into_expression(b)
        return wrap_expr(plr.cov(a_pyexpr, b_pyexpr, ddof))


class _map_batches_wrapper:
    def __init__(
        self,
        function: Callable[[Sequence[Series]], Series | Any],
        *,
        returns_scalar: bool,
    ) -> None:
        self.function = function

View on GitHub (pinned to fe841f959e)