diff options
| author | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-17 14:13:32 -0700 |
|---|---|---|
| committer | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-17 14:13:32 -0700 |
| commit | 007b63cfeef0a6206dcfb5208c9222c6c5d977b3 (patch) | |
| tree | 8421862c2bee5c6ffcb6eafd032477eb4448daee /backend/app | |
| parent | 5cced76ce44db80b6f45021152153138e0c8bc5b (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'backend/app')
| -rw-r--r-- | backend/app/services/data_service.py | 17 |
1 files changed, 12 insertions, 5 deletions
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: |
