pola-rs/polars · error · ValueError

expected at least one Series in 'corr' inputs if…

Error message

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

What it means

`pl.corr(a, b, eager=True)` builds a DataFrame from whichever inputs are Series; if neither `a` nor `b` is a Series there is no frame to compute on, so it raises ValueError. In eager mode at least one input must be a concrete Series; strings/expressions are only allowed alongside one.

Solutions

  1. Pass at least one `pl.Series` to `corr` when using `eager=True`
  2. Drop `eager=True` and use `df.select(pl.corr("a", "b"))` for string/expr inputs
  3. Convert a column to a Series first: `df["a"]`

Example fix

// before
pl.corr("a", "b", eager=True)
// after
pl.corr(df["a"], df["b"], eager=True)
# or lazily:
df.select(pl.corr("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("corr(eager=True) needs at least one pl.Series")

Type guard

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

Try / catch

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

Prevention

When it happens

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

Common situations: Copy-pasting lazy-style string column names into an eager call; assuming eager mode resolves column names like the lazy API does.

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/62fc96410c67a86a. Report an issue: GitHub.

Appendix: source

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

    >>> s1 = pl.Series("a", [1, 8, 3])
    >>> s2 = pl.Series("b", [4, 5, 2])
    >>> pl.corr(s1, s2, eager=True)
    shape: (1,)
    Series: 'a' [f64]
    [
        0.544705
    ]
    >>> pl.corr(s1, s2, method="spearman", eager=True)
    shape: (1,)
    Series: 'a' [f64]
    [
        0.5
    ]
    """
    if eager:
        if not (isinstance(a, pl.Series) or isinstance(b, pl.Series)):
            msg = "expected at least one Series in 'corr' 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(
            corr(*exprs, eager=False, method=method, propagate_nans=propagate_nans)
        ).to_series()
    else:
        a_pyexpr = parse_into_expression(a)
        b_pyexpr = parse_into_expression(b)

        if method == "pearson":
            return wrap_expr(plr.pearson_corr(a_pyexpr, b_pyexpr))
        elif method == "spearman":
            return wrap_expr(plr.spearman_rank_corr(a_pyexpr, b_pyexpr, propagate_nans))
        else:
            msg = f"method must be one of {{'pearson', 'spearman'}}, got {method!r}"
            raise ValueError(msg)

View on GitHub (pinned to fe841f959e)