Python
fix(dataflows): stop telling a historical run today's date
Yijia-Xiaob4479b0c700b
diff --git a/tests/test_fundamentals_lookahead.py b/tests/test_fundamentals_lookahead.pyindex 696b14872..5c4bd02fb 100644--- a/tests/test_fundamentals_lookahead.py+++ b/tests/test_fundamentals_lookahead.py@@ -110,7 +110,6 @@ class TestLiveRunUnchanged:out = _yf(_TODAY)for value in _LEAKY:assert value in out- assert "Data retrieved on:" in outassert "withheld" not in outdef test_yfinance_absent_curr_date_returns_the_full_profile(self):diff --git a/tests/test_undated_tools_as_of.py b/tests/test_undated_tools_as_of.pyindex 84c91e1bb..3570d7c2e 100644--- a/tests/test_undated_tools_as_of.py+++ b/tests/test_undated_tools_as_of.py@@ -246,3 +246,28 @@ def test_the_price_path_also_tells_an_outage_from_an_unknown_symbol(monkeypatch)monkeypatch.setattr(stockstats_utils, "vendor_reachable", lambda url: True)with pytest.raises(NoMarketDataError):y_finance.get_YFin_data_online("AAPL", "2026-09-01", "2026-09-10")++[email protected]("func, args", [+ ("get_YFin_data_online", ("AAPL", "2025-06-02", "2025-06-06")),+ ("get_balance_sheet", ("AAPL", "quarterly", "2025-06-06")),+ ("get_cashflow", ("AAPL", "quarterly", "2025-06-06")),+ ("get_income_statement", ("AAPL", "quarterly", "2025-06-06")),+ ("get_insider_transactions", ("AAPL", "2025-06-06")),+])+def test_a_historical_run_is_not_told_todays_date(func, args):+ """A header stamped with the wall clock tells a backtest when it is really running."""+ from datetime import date++ statement = pd.DataFrame({pd.Timestamp("2025-03-31"): [1.0]}, index=["Total Assets"])+ prices = pd.DataFrame({"Open": [1.0], "High": [1.0], "Low": [1.0], "Close": [1.0], "Volume": [1]},+ index=pd.DatetimeIndex(["2025-06-02"], name="Date"))+ ticker = mock.Mock(quarterly_balance_sheet=statement, quarterly_cashflow=statement,+ quarterly_income_stmt=statement,+ insider_transactions=_insider_frame("2025-05-30"),+ history=lambda **k: prices)+ with mock.patch.object(y_finance.yf, "Ticker", return_value=ticker):+ out = getattr(y_finance, func)(*args)++ assert date.today().isoformat() not in outdiff --git a/tradingagents/dataflows/y_finance.py b/tradingagents/dataflows/y_finance.pyindex c2f24f35d..a523cede5 100644--- a/tradingagents/dataflows/y_finance.py+++ b/tradingagents/dataflows/y_finance.py@@ -71,8 +71,7 @@ def get_YFin_data_online(# agent (and user) can see which instrument was actually priced.label = canonical if canonical == symbol.upper() else f"{canonical} (from {symbol})"header = f"# Stock data for {label} from {start_date} to {end_date}\n"- header += f"# Total records: {len(data)}\n"- header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"+ header += f"# Total records: {len(data)}\n\n"return header + csv_string@@ -345,8 +344,7 @@ def get_fundamentals(if not lines:raise NoMarketDataError(ticker, canonical, "no fundamental fields returned")- header = f"# Company Fundamentals for {canonical}\n"- header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"+ header = f"# Company Fundamentals for {canonical}\n\n"return header + "\n".join(lines)@@ -381,7 +379,6 @@ def get_balance_sheet(# Add header informationheader = f"# Balance Sheet data for {canonical} ({freq})\n"- header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"header += _PERIOD_END_VINTAGEreturn header + csv_string@@ -417,7 +414,6 @@ def get_cashflow(# Add header informationheader = f"# Cash Flow data for {canonical} ({freq})\n"- header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"header += _PERIOD_END_VINTAGEreturn header + csv_string@@ -453,7 +449,6 @@ def get_income_statement(# Add header informationheader = f"# Income Statement data for {canonical} ({freq})\n"- header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"header += _PERIOD_END_VINTAGEreturn header + csv_string@@ -518,7 +513,6 @@ def get_insider_transactions(# Add header informationheader = f"# Insider Transactions data for {canonical}\n"- header += f"# Data retrieved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"header += _TRANSACTION_DATE_VINTAGEreturn header + csv_string