ZhuLinsen/daily_stock_analysis · error · ValueError
daily data missing {missing_text} column
Error message
daily data missing {missing_text} column What it means
Raised in the daily-bar normalization helper of src/services/alert_indicators.py:201 when building the canonical OHLCV frame: for each required canonical column (open/high/low/close/volume style names), _find_column tries case-insensitive aliases in the source DataFrame, and any column with no resolvable alias is collected and reported, comma-joined, in this error. The evaluator refuses to compute indicators on frames missing required inputs.
Source
Thrown at src/services/alert_indicators.py:201
) -> pd.DataFrame:
if df is None or getattr(df, "empty", True):
return pd.DataFrame()
if not isinstance(df, pd.DataFrame):
return pd.DataFrame()
output = pd.DataFrame(index=df.index.copy())
output["date"] = _date_series(df)
missing = []
for canonical in required_columns:
source = _find_column(df, canonical)
if source is None:
missing.append(canonical)
continue
output[canonical] = pd.to_numeric(df[source], errors="coerce")
if missing:
missing_text = ", ".join(missing)
raise ValueError(f"daily data missing {missing_text} column")
output = output.dropna(subset=list(required_columns)).copy()
if output.empty:
return output
output = _drop_partial_today(output, now=now)
if output.empty:
return output.reset_index(drop=True)
output = output.sort_values(by="date", kind="stable", na_position="first").reset_index(drop=True)
return output
def _evaluate_ma(stock_code: str, params: Dict[str, Any], df: pd.DataFrame) -> IndicatorEvaluation:
window = int(params["window"])
direction = str(params["direction"])
series = df["close"].rolling(window=window).mean()
latest = _latest_timestamp(df)
prev_close, curr_close = float(df["close"].iloc[-2]), float(df["close"].iloc[-1])
prev_ma, curr_ma = float(series.iloc[-2]), float(series.iloc[-1])View on GitHub (pinned to 5159bd72e8)
Solutions
- Rename the DataFrame columns to the canonical names (or a supported alias) before evaluation: df = df.rename(columns={'vol': 'volume'}).
- If a provider changed its schema, update _find_column's alias map (or the provider adapter's standardization) to cover the new name.
- Log df.columns.tolist() when the error fires to see exactly which alias is missing.
Example fix
# before
df = pd.read_csv('bars.csv') # columns: date, open, high, low, close, vol
eval = evaluate_alert(rule, df)
# after
df = pd.read_csv('bars.csv').rename(columns={'vol': 'volume'})
eval = evaluate_alert(rule, df) Defensive patterns
Strategy: validation
Validate before calling
CANONICAL = {'open', 'high', 'low', 'close', 'volume'}
missing = CANONICAL - set(map(str.lower, df.columns))
if missing:
df = df.rename(columns=ALIAS_MAP) # or raise a clear upstream error
if CANONICAL - set(map(str.lower, df.columns)):
raise ValueError(f'bar data lacks canonical columns: {missing}') Type guard
def has_required_bar_columns(df) -> bool:
cols = {str(c).strip().lower() for c in df.columns}
return {'open','high','low','close','volume'} <= cols # adjust to the canonical set in _find_column Try / catch
try:
evaluation = evaluate_indicator(alert, df)
except ValueError as e:
if 'daily data missing' in str(e):
logger.error('column mismatch: %s vs %s', df.columns.tolist(), e)
return skip_rule(alert, reason='bad_source_columns')
raise Prevention
- Standardize column names in the data-provider adapter, not at evaluation time.
- Add alias-table unit tests whenever a provider's schema changes.
- Log df.columns on any 'daily data missing' error so alias gaps are found in minutes.
When it happens
Trigger: Evaluating a technical alert against a daily K-line DataFrame whose columns are abbreviated (e.g. only '开盘'/'收盘' Chinese names not in the alias map), renamed by a data-provider change (e.g. 'vol' removed in favor of 'volume' when the alias table only maps one), or a DataFrame of weekly/monthly bars with different column naming.
Common situations: A data provider in data_provider/ changes its column schema after an upgrade; a user feeds cached CSV data with hand-edited headers; a new market (HK/US) returns English-only headers missing an alias the A-share provider had.
Related errors
- fast_period must be < slow_period
- {alert_type} periods require {required_bars} bars, but at mo
- not_found
- unsupported alert_type for current EventMonitor runtime: {al
- unsupported alert_type: {alert_type}
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/dc0a50c747a92a49.
Report an issue: GitHub.