Skip to content

Commit 13e34c2

Browse files
committed
fix: guard against empty df in regression fallback and preprocessing
1 parent 42989f4 commit 13e34c2

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

backend/app/services/preprocessing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def add_momentum(df: pd.DataFrame, window: int = 10) -> pd.DataFrame:
7272

7373
def preprocess_symbol_data(df: pd.DataFrame, period_type: str = "daily") -> pd.DataFrame:
7474
"""Full preprocessing pipeline for a single symbol with adaptive windows."""
75+
if df is None or df.empty or len(df) < 2:
76+
return pd.DataFrame()
7577
data = clean_price_data(df)
7678
data = add_returns(data)
7779

backend/app/services/regression_predictor.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,16 @@ def predict_all_regression(
154154
)
155155
comparisons[symbol] = result["model_comparison"]
156156
except (ValueError, Exception):
157-
# Fallback: use recent momentum as simple prediction
157+
if len(df) == 0:
158+
predictions.append({
159+
"symbol": symbol,
160+
"latest_price": 0.0,
161+
"predicted_return": 0.0,
162+
"trend": "neutral",
163+
"confidence": 0.0,
164+
"model_used": "no_data_fallback",
165+
})
166+
continue
158167
mom = float(df["momentum"].iloc[-1]) if "momentum" in df.columns else 0.0
159168
predictions.append(
160169
{

0 commit comments

Comments
 (0)