{"record":{"id":"d10478d873bfb199","repo":"pola-rs/polars","slug":"require-0-alpha-1-found-alpha-r","errorCode":null,"errorMessage":"require 0 < `alpha` <= 1 (found {alpha!r})","messagePattern":"require 0 < `alpha` <= 1 \\(found (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/expr/expr.py","lineNumber":12818,"sourceCode":"    elif span is not None:\n        if span < 1.0:\n            msg = f\"require `span` >= 1 (found {span!r})\"\n            raise ValueError(msg)\n        alpha = 2.0 / (span + 1.0)\n\n    elif half_life is not None:\n        if half_life <= 0.0:\n            msg = f\"require `half_life` > 0 (found {half_life!r})\"\n            raise ValueError(msg)\n        alpha = 1.0 - math.exp(-math.log(2.0) / half_life)\n\n    elif alpha is None:\n        msg = \"one of `com`, `span`, `half_life`, or `alpha` must be set\"\n        raise ValueError(msg)\n\n    elif not (0 < alpha <= 1):\n        msg = f\"require 0 < `alpha` <= 1 (found {alpha!r})\"\n        raise ValueError(msg)\n\n    return alpha\n\n\ndef _prepare_rolling_by_window_args(window_size: timedelta | str) -> str:\n    if isinstance(window_size, timedelta):\n        window_size = parse_as_duration_string(window_size)\n    return window_size\n","sourceCodeStart":12800,"sourceCodeEnd":12827,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/expr/expr.py#L12800-L12827","documentation":"_prepare_alpha's final validation: an explicitly supplied alpha must satisfy 0 < alpha <= 1, since alpha is a smoothing weight (1 means no smoothing, values approaching 0 mean near-total smoothing, and 0 itself would zero out all updates). The check is inclusive of 1 but exclusive of 0, and reports the found value.","triggerScenarios":"pl.col('x').ewm_mean(alpha=1.5), ewm_mean(alpha=0), or alpha derived from arithmetic that can leave the range (e.g. unnormalised weights).","commonSituations":"Computing alpha from ratios without clamping; porting formulas where alpha is defined as 1 - lambda and lambda went negative; UI sliders exposing 0..1 inclusive where 0 gets forwarded.","solutions":["Clamp or fix alpha into (0, 1]: alpha = min(max(alpha, _EPS), 1.0).","Re-derive alpha from span/com if the direct value is unreliable.","Reject out-of-range alphas at input parsing with a clear domain error."],"exampleFix":"# before\npl.col('x').ewm_mean(alpha=1.5)\n\n# after\npl.col('x').ewm_mean(alpha=min(alpha, 1.0))","handlingStrategy":"validation","validationCode":"if alpha is not None:\n    assert 0 < alpha <= 1, f'alpha out of range: {alpha!r}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["alpha is a weight: exactly 1 is fine, 0 is not.","Clamp computed ratios before passing them as alpha."],"tags":["validation","polars","expression","ewm","statistics"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}