From b8684f573438fe3bbb0ae59df3167698fc93bdc2 Mon Sep 17 00:00:00 2001 From: Gaze31 Date: Sat, 18 Apr 2026 09:26:26 +0530 Subject: [PATCH 1/4] fix: handle YFPricesMissingError in get_history_metadata when intraday unavailable (#2745) --- yfinance/scrapers/history.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/yfinance/scrapers/history.py b/yfinance/scrapers/history.py index 578710b5a..726106f35 100644 --- a/yfinance/scrapers/history.py +++ b/yfinance/scrapers/history.py @@ -546,15 +546,12 @@ def _get_history_cache(self, period="max", interval="1d", repair=False) -> pd.Da return self._history_cache[cache_key] def get_history_metadata(self) -> dict: - if self._history_metadata is None or 'tradingPeriods' not in self._history_metadata: - # Request intraday data, because then Yahoo returns exchange schedule (tradingPeriods). + if self._history_metadata is None or 'tradingPeriods' not in self._history_metadata: + # Request intraday data, because then Yahoo returns exchange schedule (tradingPeriods). + try: self._get_history_cache(period="5d", interval="1h")['prices'] - - if self._history_metadata_formatted is False: - self._history_metadata = utils.format_history_metadata(self._history_metadata) - self._history_metadata_formatted = True - - return self._history_metadata + except Exception: + pass # tradingPeriods is optional enrichment; don't fail if intraday unavailable def get_dividends(self, period="max", repair=False) -> pd.Series: return self._get_history_cache(interval='1d', period=period, repair=repair)['dividends'] From 591c6f562d930fee60be395e5e6d53a433a67070 Mon Sep 17 00:00:00 2001 From: Gaze31 Date: Sat, 18 Apr 2026 20:15:23 +0530 Subject: [PATCH 2/4] restore blank line between try/except and metadata format check --- yfinance/scrapers/history.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/yfinance/scrapers/history.py b/yfinance/scrapers/history.py index 726106f35..ef2f1c41b 100644 --- a/yfinance/scrapers/history.py +++ b/yfinance/scrapers/history.py @@ -546,13 +546,18 @@ def _get_history_cache(self, period="max", interval="1d", repair=False) -> pd.Da return self._history_cache[cache_key] def get_history_metadata(self) -> dict: - if self._history_metadata is None or 'tradingPeriods' not in self._history_metadata: - # Request intraday data, because then Yahoo returns exchange schedule (tradingPeriods). - try: - self._get_history_cache(period="5d", interval="1h")['prices'] - except Exception: - pass # tradingPeriods is optional enrichment; don't fail if intraday unavailable + def get_history_metadata(self) -> dict: + if self._history_metadata is None or 'tradingPeriods' not in self._history_metadata: + try: + self._get_history_cache(period="5d", interval="1h")['prices'] + except Exception: + pass # tradingPeriods is optional enrichment; don't fail if intraday unavailable + + if self._history_metadata_formatted is False: + self._history_metadata = utils.format_history_metadata(self._history_metadata) + self._history_metadata_formatted = True + return self._history_metadata def get_dividends(self, period="max", repair=False) -> pd.Series: return self._get_history_cache(interval='1d', period=period, repair=repair)['dividends'] From 58db854379f6fa38faaa9bb0d413cfe833a0ec47 Mon Sep 17 00:00:00 2001 From: Gaze31 Date: Sun, 19 Apr 2026 10:02:59 +0530 Subject: [PATCH 3/4] fix: correct nested function definition and restore blank line --- yfinance/scrapers/history.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yfinance/scrapers/history.py b/yfinance/scrapers/history.py index ef2f1c41b..60a75d88a 100644 --- a/yfinance/scrapers/history.py +++ b/yfinance/scrapers/history.py @@ -546,8 +546,8 @@ def _get_history_cache(self, period="max", interval="1d", repair=False) -> pd.Da return self._history_cache[cache_key] def get_history_metadata(self) -> dict: - def get_history_metadata(self) -> dict: if self._history_metadata is None or 'tradingPeriods' not in self._history_metadata: + # Request intraday data, because then Yahoo returns exchange schedule (tradingPeriods). try: self._get_history_cache(period="5d", interval="1h")['prices'] except Exception: @@ -558,6 +558,8 @@ def get_history_metadata(self) -> dict: self._history_metadata_formatted = True return self._history_metadata + + return self._history_metadata def get_dividends(self, period="max", repair=False) -> pd.Series: return self._get_history_cache(interval='1d', period=period, repair=repair)['dividends'] From bba19f0d25d0d610bb22763a3bcd8c2aa3ef5076 Mon Sep 17 00:00:00 2001 From: Gaze31 Date: Sun, 19 Apr 2026 10:10:47 +0530 Subject: [PATCH 4/4] fix: wrap tradingPeriods fetch in try/except to handle YFPricesMissingError --- yfinance/scrapers/history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yfinance/scrapers/history.py b/yfinance/scrapers/history.py index 60a75d88a..35ff7b710 100644 --- a/yfinance/scrapers/history.py +++ b/yfinance/scrapers/history.py @@ -553,13 +553,13 @@ def get_history_metadata(self) -> dict: except Exception: pass # tradingPeriods is optional enrichment; don't fail if intraday unavailable + if self._history_metadata_formatted is False: self._history_metadata = utils.format_history_metadata(self._history_metadata) self._history_metadata_formatted = True return self._history_metadata - return self._history_metadata def get_dividends(self, period="max", repair=False) -> pd.Series: return self._get_history_cache(interval='1d', period=period, repair=repair)['dividends']