mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-26 22:42:40 +03:00
fix(yahoo): clean OHLCV frames on their own copy
- dropping undated rows copies the frame before prices are coerced, so no chained-assignment write
This commit is contained in:
@@ -6,6 +6,8 @@ instead of `Date`, which would otherwise silently drop every indicator.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import warnings
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
@@ -68,3 +70,12 @@ class TestCleanDataframeAcrossVersions:
|
||||
df["close_5_sma"] # triggers calculation
|
||||
assert "close_5_sma" in df.columns
|
||||
assert df["close_5_sma"].notna().any()
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_cleaning_a_frame_with_undated_rows_writes_to_its_own_copy():
|
||||
raw = pd.DataFrame({"Date": ["2026-01-08", None, "2026-01-09"], "Close": ["1", "2", "x"]})
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("error")
|
||||
cleaned = ohlcv._clean_dataframe(raw)
|
||||
assert cleaned["Close"].tolist()[0] == 1.0
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ def _clean_dataframe(data: pd.DataFrame) -> pd.DataFrame:
|
||||
the latest in-range bar (#1201)."""
|
||||
data = _ensure_date_column(data)
|
||||
data["Date"] = _normalize_dates(data["Date"])
|
||||
data = data.dropna(subset=["Date"])
|
||||
data = data.dropna(subset=["Date"]).copy()
|
||||
|
||||
price_cols = [c for c in ["Open", "High", "Low", "Close", "Volume"] if c in data.columns]
|
||||
data[price_cols] = data[price_cols].apply(pd.to_numeric, errors="coerce")
|
||||
|
||||
Reference in New Issue
Block a user