HKUDS/Vibe-Trading · error · ValueError
ts_max window must be >= 1, got {n}
Error message
ts_max window must be >= 1, got {n} What it means
ts_max computes a rolling maximum per column with a warmup of NaN. The window parameter n must be a positive integer because pandas rolling requires window >= 1; n < 1 (zero or negative) is rejected before calling pandas to fail fast with a clear message.
Source
Thrown at agent/src/factors/base.py:196
def ts_mean(df: pd.DataFrame, n: int) -> pd.DataFrame:
"""Rolling mean per column, warmup → NaN."""
if n < 1:
raise ValueError(f"ts_mean window must be >= 1, got {n}")
return df.rolling(window=n, min_periods=n).mean()
def ts_std(df: pd.DataFrame, n: int) -> pd.DataFrame:
"""Rolling sample std (ddof=1) per column, warmup → NaN."""
if n < 2:
raise ValueError(f"ts_std window must be >= 2, got {n}")
return df.rolling(window=n, min_periods=n).std(ddof=1)
def ts_max(df: pd.DataFrame, n: int) -> pd.DataFrame:
"""Rolling max per column, warmup → NaN."""
if n < 1:
raise ValueError(f"ts_max window must be >= 1, got {n}")
return df.rolling(window=n, min_periods=n).max()
def ts_min(df: pd.DataFrame, n: int) -> pd.DataFrame:
"""Rolling min per column, warmup → NaN."""
if n < 1:
raise ValueError(f"ts_min window must be >= 1, got {n}")
return df.rolling(window=n, min_periods=n).min()
def _argmax_last(arr: np.ndarray) -> float:
if np.isnan(arr).all():
return np.nan
arr_filled = np.where(np.isnan(arr), -np.inf, arr)
return float(np.argmax(arr_filled))
def _argmin_last(arr: np.ndarray) -> float:View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass a window >= 1, e.g. ts_max(df, 5)
- Validate windows in config/loading before calling compute()
- If windows come from arithmetic, clamp: max(1, n)
Example fix
// before ts_max(df, 0) // after ts_max(df, max(1, window))
Defensive patterns
Strategy: validation
Validate before calling
if not isinstance(n, int) or n < 1: raise ValueError(f'window must be int >= 1, got {n!r}') Type guard
def is_valid_window(n: object) -> bool:
return isinstance(n, int) and not isinstance(n, bool) and n >= 1 Prevention
- Validate all window params at config load time
- Never compute windows without clamping to >= 1
When it happens
Trigger: Calling ts_max(df, 0), ts_max(df, -3), or passing a window derived from config/user input that evaluates to a non-positive integer.
Common situations: Config typos (window: 0), computing windows from expressions like len(df) - horizon that hit 0 on short data, or looping over a list of windows that accidentally includes 0.
Related errors
- ts_min window must be >= 1, got {n}
- decay_linear window must be >= 1, got {n}
- fit_ornstein_uhlenbeck needs a series that varies; this one
- __series__ needs a 'values' list
- __dataframe__ needs a 'data' list of rows
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/e0d7b225730f7fc3.
Report an issue: GitHub.