HKUDS/Vibe-Trading · error · ValueError
ts_min window must be >= 1, got {n}
Error message
ts_min window must be >= 1, got {n} What it means
ts_min computes a rolling minimum per column with NaN warmup. Like ts_max it requires window n >= 1 since pandas rolling cannot accept zero/negative windows; the guard raises ValueError before pandas does.
Source
Thrown at agent/src/factors/base.py:203
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:
if np.isnan(arr).all():
return np.nan
arr_filled = np.where(np.isnan(arr), np.inf, arr)
return float(np.argmin(arr_filled))
def ts_argmax(df: pd.DataFrame, n: int) -> pd.DataFrame:View on GitHub (pinned to 80ffdda44c)
Solutions
- Use a window >= 1
- Validate factor spec windows at load time
- Clamp computed windows with max(1, n)
Example fix
// before
ts_min(df, n)
// after
if n < 1: raise ValueError('window must be >= 1')
ts_min(df, n) 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 window specs once in a config schema
- Add unit tests for boundary windows (0, 1, negative)
When it happens
Trigger: Calling ts_min(df, 0) or ts_min(df, -1), or a parameterized factor spec with a bad window value.
Common situations: YAML/JSON factor configs with window: 0, dynamically computed windows on tiny datasets, or copy-paste from a spec using a different convention (0-based windows).
Related errors
- ts_max 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/7fcc47e8e17b0fe5.
Report an issue: GitHub.