From 007b63cfeef0a6206dcfb5208c9222c6c5d977b3 Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Sun, 17 May 2026 14:13:32 -0700 Subject: Fix _json_value crashing on array-valued yfinance info fields pd.isna() on a numpy array returns an array, not a scalar, causing ValueError in the boolean context. Wrapping in try/except restores get_company_info() for tickers like NFLX whose .info includes array fields. Also suppress FutureWarning in compute_beta pct_change calls. Co-Authored-By: Claude Sonnet 4.6 --- backend/app/services/data_service.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'backend') diff --git a/backend/app/services/data_service.py b/backend/app/services/data_service.py index 31bdb05..95650ad 100644 --- a/backend/app/services/data_service.py +++ b/backend/app/services/data_service.py @@ -58,7 +58,10 @@ def _json_value(value: Any) -> Any: return None if isinstance(value, pd.Timestamp): return value.isoformat() - if pd.isna(value): + try: + if pd.isna(value): + return None + except (TypeError, ValueError): return None if hasattr(value, "item"): return _json_value(value.item()) @@ -653,10 +656,14 @@ def compute_beta(symbol: str) -> float | None: try: ticker_closes = {row["date"]: row["close"] for row in ticker_history if row.get("close") is not None} spy_closes = {row["date"]: row["close"] for row in spy_history if row.get("close") is not None} - ticker_series = pd.Series(ticker_closes).sort_index() - spy_series = pd.Series(spy_closes).sort_index() - ticker_weekly = ticker_series.resample("W").last().pct_change().dropna() - spy_weekly = spy_series.resample("W").last().pct_change().dropna() + ticker_series = pd.Series(ticker_closes, dtype=float) + ticker_series.index = pd.to_datetime(ticker_series.index) + ticker_series = ticker_series.sort_index() + spy_series = pd.Series(spy_closes, dtype=float) + spy_series.index = pd.to_datetime(spy_series.index) + spy_series = spy_series.sort_index() + ticker_weekly = ticker_series.resample("W").last().pct_change(fill_method=None).dropna() + spy_weekly = spy_series.resample("W").last().pct_change(fill_method=None).dropna() aligned = pd.concat([ticker_weekly, spy_weekly], axis=1, join="inner").dropna() aligned.columns = ["ticker", "spy"] if len(aligned) < 52: -- cgit v1.3-2-g0d8e