fix: Add validation checks for missing 'close' column in stock data
This commit is contained in:
parent
6be64ebe03
commit
b4312e92d4
@ -82,17 +82,24 @@ def run_atr_ema_target_scanner(min_price: float, max_price: float, min_volume: i
|
||||
try:
|
||||
df = get_stock_data(ticker, start_date, end_date, interval)
|
||||
|
||||
# **Check if DataFrame has expected columns**
|
||||
# VALIDATION CHECKS - BEGIN
|
||||
required_columns = ['date', 'open', 'high', 'low', 'close', 'volume']
|
||||
if df.empty:
|
||||
print(f"⚠️ No data found for {ticker}. Skipping.")
|
||||
print(f"⚠️ {ticker}: Empty DataFrame from get_stock_data()")
|
||||
continue
|
||||
|
||||
missing_cols = [col for col in ["close", "open", "high", "low", "volume"] if col not in df.columns]
|
||||
missing_cols = set(required_columns) - set(df.columns)
|
||||
if missing_cols:
|
||||
print(f"⚠️ {ticker} data is missing columns: {missing_cols}. Skipping.")
|
||||
print(df.head()) # Debugging output
|
||||
print(f"⚠️ {ticker}: Missing columns {missing_cols} in DataFrame")
|
||||
print(f"Actual columns: {df.columns.tolist()}")
|
||||
continue
|
||||
|
||||
if 'close' not in df.columns:
|
||||
print(f"⚠️ {ticker}: 'close' column missing, cannot process")
|
||||
print(f"Available columns: {df.columns.tolist()}")
|
||||
continue
|
||||
# VALIDATION CHECKS - END
|
||||
|
||||
results = indicator.calculate(df)
|
||||
last_row = results.iloc[-1]
|
||||
prev_row = results.iloc[-2]
|
||||
|
||||
@ -88,9 +88,12 @@ def get_stock_data(ticker: str, start_date: datetime, end_date: datetime, interv
|
||||
df = pd.DataFrame(
|
||||
result.result_rows,
|
||||
columns=['date', 'open', 'high', 'low', 'close', 'volume']
|
||||
)
|
||||
).dropna(subset=['close']) # Filter out rows with null close prices
|
||||
|
||||
# Convert date column if needed
|
||||
if df.empty or 'close' not in df.columns:
|
||||
return pd.DataFrame()
|
||||
|
||||
if df['date'].dtype == object:
|
||||
df['date'] = pd.to_datetime(df['date'])
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user