HKUDS/Vibe-Trading · error · ValueError
window must be >= 1, got {window}
Error message
window must be >= 1, got {window} What it means
find_peaks_valleys uses a centered window of size 2*window+1 for local-extrema detection; window < 1 makes the comparison meaningless (and would break slicing), so it raises immediately. Note: too-short series (n < 2*window+1) do NOT raise — they return empty peak/valley lists.
Source
Thrown at agent/src/tools/pattern_tool.py:35
from src.tools.path_utils import safe_run_dir
# ---------------------------------------------------------------------------
# Pattern detection functions
# ---------------------------------------------------------------------------
def find_peaks_valleys(close: pd.Series, window: int = 5) -> dict:
"""Detect peaks and valleys in a price series.
Args:
close: Closing price series.
window: Half-window size; effective window is 2*window+1.
Returns:
Dict with keys "peaks" and "valleys", each a list of integer indices.
"""
if window < 1:
raise ValueError(f"window must be >= 1, got {window}")
n = len(close)
if n < 2 * window + 1:
return {"peaks": [], "valleys": []}
values = close.values.astype(float)
peaks, valleys = [], []
for i in range(window, n - window):
seg = values[i - window : i + window + 1]
if np.isnan(values[i]):
continue
seg = seg[~np.isnan(seg)]
if len(seg) == 0:
continue
if values[i] == np.max(seg):
peaks.append(i)
if values[i] == np.min(seg):
valleys.append(i)View on GitHub (pinned to 80ffdda44c)
Solutions
- Use window >= 1 (typical 3–5)
- Clamp: window = max(1, int(user_value))
- Validate pattern_tool params before dispatch
Example fix
# before find_peaks_valleys(close, window=0) # after find_peaks_valleys(close, window=max(1, window))
Defensive patterns
Strategy: validation
Validate before calling
window = int(window)
if window < 1:
raise ArgumentError("window must be >= 1")
# short series return empty results, not errors Type guard
def valid_peak_window(w: object) -> bool:
return isinstance(w, int) and w >= 1 Try / catch
try:
pivots = find_peaks_valleys(close, window=window)
except ValueError as e:
if "window must be >= 1" in str(e):
pivots = find_peaks_valleys(close, window=max(1, window)) Prevention
- Clamp user tuning params to tool minimums
- Keep separate window knobs for peaks vs slope (min 1 vs min 2)
- Check series length vs 2*window+1 to anticipate empty results
When it happens
Trigger: Calling find_peaks_valleys (or pattern tools support_resistance/head_and_shoulders/double_top_bottom/triangle/broadening that forward a window) with window=0 or a negative value.
Common situations: Defaulting window to 0 in config, or computing window from a tunable that can be zero.
Related errors
- window must be >= 2, got {window}
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
- delay requires n >= 1 (lookahead ban)
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/8fb34e831774d143.
Report an issue: GitHub.