{"record":{"id":"62fc96410c67a86a","repo":"pola-rs/polars","slug":"expected-at-least-one-series-in-corr-inputs-if","errorCode":null,"errorMessage":"expected at least one Series in 'corr' inputs if 'eager=True'","messagePattern":"expected at least one Series in 'corr' inputs if 'eager=True'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/lazy.py","lineNumber":965,"sourceCode":"        0.544705\n    ]\n    >>> pl.corr(s1, s2, method=\"spearman\", eager=True)\n    shape: (1,)\n    Series: 'a' [f64]\n    [\n        0.5\n    ]\n    \"\"\"\n    if ddof is not None:\n        issue_deprecation_warning(\n            \"the `ddof` parameter has no effect. Do not use it.\",\n            version=\"1.17.0\",\n        )\n\n    if eager:\n        if not (isinstance(a, pl.Series) or isinstance(b, pl.Series)):\n            msg = \"expected at least one Series in 'corr' inputs if 'eager=True'\"\n            raise ValueError(msg)\n\n        frame = pl.DataFrame([e for e in (a, b) if isinstance(e, pl.Series)])\n        exprs = ((e.name if isinstance(e, pl.Series) else e) for e in (a, b))\n        return frame.select(\n            corr(*exprs, eager=False, method=method, propagate_nans=propagate_nans)\n        ).to_series()\n    else:\n        a_pyexpr = parse_into_expression(a)\n        b_pyexpr = parse_into_expression(b)\n\n        if method == \"pearson\":\n            return wrap_expr(plr.pearson_corr(a_pyexpr, b_pyexpr))\n        elif method == \"spearman\":\n            return wrap_expr(plr.spearman_rank_corr(a_pyexpr, b_pyexpr, propagate_nans))\n        else:\n            msg = f\"method must be one of {{'pearson', 'spearman'}}, got {method!r}\"\n            raise ValueError(msg)\n","sourceCodeStart":947,"sourceCodeEnd":983,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/functions/lazy.py#L947-L983","documentation":"pl.corr(..., eager=True) computes the correlation immediately by building a one-shot DataFrame from the Series inputs, so at least one of a/b must be a pl.Series to supply rows. Two Exprs or two bare column-name strings have no data context, and the ValueError fires before anything is evaluated.","triggerScenarios":"pl.corr('a', 'b', eager=True); pl.corr(pl.col('a'), pl.col('b'), eager=True) outside a select/context; renaming a working df.select(pl.corr(...)) call into a standalone eager call.","commonSituations":"Moving a correlation out of select() into a summary function and adding eager=True; porting example code that used Series; mixing names and expressions in quick scripts.","solutions":["Pass Series: pl.corr(df['a'], df['b'], eager=True)","Or evaluate expressions in a context: df.select(pl.corr('a', 'b')).item()","Remember mixed Series + Expr works — the Expr is evaluated against the frame built from the Series"],"exampleFix":"# before\npl.corr('a', 'b', eager=True)  # ValueError\n\n# after\npl.corr(df['a'], df['b'], eager=True)\n# or\ndf.select(pl.corr('a', 'b')).item()","handlingStrategy":"validation","validationCode":"if eager and not (isinstance(a, pl.Series) or isinstance(b, pl.Series)):\n    result = df.select(pl.corr(a, b)).item()  # context-based fallback\nelse:\n    result = pl.corr(a, b, eager=eager, method=method)","typeGuard":"def has_series_input(a, b) -> bool:\n    return isinstance(a, pl.Series) or isinstance(b, pl.Series)","tryCatchPattern":null,"preventionTips":["Treat eager=True as 'I am handing you data', not 'resolve these column names now'","Prefer df.select(pl.corr(...)) inside pipelines"],"tags":["polars","corr","eager","input-validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}