{"record":{"id":"fd8a0988e4756435","repo":"HKUDS/Vibe-Trading","slug":"window-must-be-2-got-window","errorCode":null,"errorMessage":"window must be >= 2, got {window}","messagePattern":"window must be >= 2, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/pattern_tool.py","lineNumber":146,"sourceCode":"        centers.sort(reverse=True)\n        return [c for _, c in centers[:n]]\n\n    return {\"support\": cluster(valley_prices, num_levels), \"resistance\": cluster(peak_prices, num_levels)}\n\n\ndef trend_line_slope(close: pd.Series, window: int = 20) -> pd.Series:\n    \"\"\"Compute rolling linear-fit slope.\n\n    Args:\n        close: Closing price series.\n        window: Fitting window size.\n\n    Returns:\n        Series of slope values; first window-1 entries are NaN.\n    \"\"\"\n    # polyfit needs >=2 points; window=1 raises LinAlgError.\n    if window < 2:\n        raise ValueError(f\"window must be >= 2, got {window}\")\n    n = len(close)\n    slopes = np.full(n, np.nan)\n    values = close.values.astype(float)\n    x = np.arange(window, dtype=float)\n\n    for i in range(window - 1, n):\n        seg = values[i - window + 1 : i + 1]\n        if np.any(np.isnan(seg)):\n            continue\n        slopes[i] = np.polyfit(x, seg, 1)[0]\n\n    return pd.Series(slopes, index=close.index)\n\n\ndef head_and_shoulders(close: pd.Series, window: int = 10) -> pd.Series:\n    \"\"\"Detect head-and-shoulders top pattern.\n\n    Args:","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/pattern_tool.py#L128-L164","documentation":"trend_line_slope fits a polynomial per rolling window; a window of 1 gives a single point (no slope) and window=0 makes numpy.polyfit raise LinAlgError, so the guard requires window >= 2 and raises this ValueError instead.","triggerScenarios":"Calling trend_line_slope (or _trend_slope_summary) with window=1 or 0. Window=2 works and yields finite slopes.","commonSituations":"Sharing one 'window' parameter across peak detection (min 1) and slope (min 2); auto-derived windows hitting 1 on short series.","solutions":["Use window >= 2 (typical 5–20)","Clamp: window = max(2, int(value))","If you need per-point slopes, use window=2 as the floor"],"exampleFix":"# before\ntrend_line_slope(close, window=1)\n# after\ntrend_line_slope(close, window=max(2, window))","handlingStrategy":"validation","validationCode":"window = int(window)\nif window < 2:\n    raise ArgumentError(\"window must be >= 2\")","typeGuard":"def valid_slope_window(w: object) -> bool:\n    return isinstance(w, int) and w >= 2","tryCatchPattern":"try:\n    slopes = trend_line_slope(close, window=window)\nexcept ValueError as e:\n    if \"window must be >= 2\" in str(e):\n        slopes = trend_line_slope(close, window=max(2, window))","preventionTips":["Don't reuse peak-detection window defaults (1) for slope","Clamp tunables: max(2, w)","Skip slope computation for series shorter than window"],"tags":["pattern-tool","window-validation","regression"],"backgroundTag":"argument-range-validation-failed","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}