{"record":{"id":"9157e468ebeba5c4","repo":"pola-rs/polars","slug":"method-must-be-one-of-pearson-spearman-g","errorCode":null,"errorMessage":"method must be one of {{'pearson', 'spearman'}}, got {method!r}","messagePattern":"method must be one of (.+?)\\}, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/lazy.py","lineNumber":982,"sourceCode":"            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\n\n@overload\ndef cov(\n    a: IntoExpr,\n    b: IntoExpr,\n    *,\n    ddof: int = ...,\n    eager: Literal[False] = ...,\n) -> Expr: ...\n\n\n@overload\ndef cov(\n    a: IntoExpr,\n    b: IntoExpr,\n    *,\n    ddof: int = ...,","sourceCodeStart":964,"sourceCodeEnd":1000,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/functions/lazy.py#L964-L1000","documentation":"pl.corr accepts exactly two methods, 'pearson' and 'spearman'; anything else raises ValueError listing the allowed pair. Kendall correlation is not implemented natively, and old/alternate spellings like 'spearman_rank' or wrong-case 'Pearson' are rejected.","triggerScenarios":"pl.corr(a, b, method='kendall'); method='spearman_rank'; method='Pearson'; a method string read from config or CLI and forwarded unvalidated.","commonSituations":"Porting scipy.stats vocabulary; stale option names after upgrades; case-sensitive config values.","solutions":["Use method='spearman' for rank correlation or 'pearson' for linear","For Kendall tau, drop to scipy.stats.kendalltau on the Series' .to_numpy() output","Normalize config strings (strip + lower) and whitelist them at load time"],"exampleFix":"# before\npl.corr(s1, s2, method='kendall')  # ValueError\n\n# after (spearman is the supported rank correlation)\npl.corr(s1, s2, method='spearman')","handlingStrategy":"validation","validationCode":"method = method.strip().lower()\nif method not in ('pearson', 'spearman'):\n    raise ValueError(f\"method must be 'pearson' or 'spearman', got {method!r}\")\nresult = pl.corr(a, b, method=method, eager=eager)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Annotate method as CorrelationMethod (Literal) so type checkers flag bad values","Whitelist user-supplied method strings before forwarding to pl.corr"],"tags":["polars","corr","literal","validation"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}