File /opt/homebrew/lib/python3.11/site-packages/yfinance/utils.py:104, in log_indent_decorator..wrapper(*args, *kwargs)
101 logger.debug(f'Entering {func.name}()')
103 with IndentationContext():
--> 104 result = func(args, **kwargs)
106 logger.debug(f'Exiting {func.name}()')
107 return result
File /opt/homebrew/lib/python3.11/site-packages/yfinance/base.py:634, in TickerBase.get_earnings_dates(self, limit, proxy)
632 cn = "Earnings Date"
633 # - remove AM/PM and timezone from date string
--> 634 tzinfo = dates[cn].str.extract('([AP]M[a-zA-Z])$')
635 dates[cn] = dates[cn].replace(' [AP]M[a-zA-Z]$', '', regex=True)
636 # - split AM/PM from timezone
File /opt/homebrew/lib/python3.11/site-packages/pandas/core/frame.py:4102, in DataFrame.getitem(self, key)
4100 if self.columns.nlevels > 1:
4101 return self._getitem_multilevel(key)
-> 4102 indexer = self.columns.get_loc(key)
4103 if is_integer(indexer):
4104 indexer = [indexer]
File /opt/homebrew/lib/python3.11/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3807 if isinstance(casted_key, slice) or (
3808 isinstance(casted_key, abc.Iterable)
3809 and any(isinstance(x, slice) for x in casted_key)
3810 ):
3811 raise InvalidIndexError(key)
-> 3812 raise KeyError(key) from err
3813 except TypeError:
3814 # If we have a listlike key, _check_indexing_error will raise
3815 # InvalidIndexError. Otherwise we fall through and re-raise
3816 # the TypeError.
3817 self._check_indexing_error(key)
I see the same issue over the last two days.
The function behind earnings_dates seems to be failing. Debugging shows an error: "An error occurred: 'Earnings Date'"
Describe bug
Hi, Earnings dates is not working due to key error.
Simple code that reproduces your problem
import yfinance as yf import pandas as pd
tkr = yf.Ticker('MSFT') display(tkr.earnings_dates)
Debug log
DEBUG Entering get_earnings_dates() DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://finance.yahoo.com/calendar/earnings?symbol=MSFT&offset=0&size=12 DEBUG params=None DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG loaded persistent cookie DEBUG reusing cookie DEBUG crumb = 'oKP7hHbieWc' DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting _make_request() DEBUG Exiting get()
KeyError Traceback (most recent call last) File /opt/homebrew/lib/python3.11/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key) 3804 try: -> 3805 return self._engine.get_loc(casted_key) 3806 except KeyError as err:
File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Earnings Date'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last) Cell In[1], line 49 12 tkr = yf.Ticker('MSFT') 14 # histo_df = tkr.history(period='max', interval='1d', auto_adjust=False) 15 # display(histo_df) 16 # display(histo_df[histo_df.index == '2003-05-18 00:00:00-04:00']) (...) 47 # - Earnings 48 # display(tkr.get_earnings_dates(limit=1000)) ---> 49 display(tkr.earnings_dates) 51 # - Dividends 52 # display(tkr.get_dividends()) 53 (...) 58 # data = tkr.funds_data 59 # display(data.top_holdings)
File /opt/homebrew/lib/python3.11/site-packages/yfinance/ticker.py:296, in Ticker.earnings_dates(self) 294 @property 295 def earnings_dates(self) -> _pd.DataFrame: --> 296 return self.get_earnings_dates()
File /opt/homebrew/lib/python3.11/site-packages/yfinance/utils.py:104, in log_indent_decorator..wrapper(*args, *kwargs)
101 logger.debug(f'Entering {func.name}()')
103 with IndentationContext():
--> 104 result = func(args, **kwargs)
106 logger.debug(f'Exiting {func.name}()')
107 return result
File /opt/homebrew/lib/python3.11/site-packages/yfinance/base.py:634, in TickerBase.get_earnings_dates(self, limit, proxy) 632 cn = "Earnings Date" 633 # - remove AM/PM and timezone from date string --> 634 tzinfo = dates[cn].str.extract('([AP]M[a-zA-Z])$') 635 dates[cn] = dates[cn].replace(' [AP]M[a-zA-Z]$', '', regex=True) 636 # - split AM/PM from timezone
File /opt/homebrew/lib/python3.11/site-packages/pandas/core/frame.py:4102, in DataFrame.getitem(self, key) 4100 if self.columns.nlevels > 1: 4101 return self._getitem_multilevel(key) -> 4102 indexer = self.columns.get_loc(key) 4103 if is_integer(indexer): 4104 indexer = [indexer]
File /opt/homebrew/lib/python3.11/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key) 3807 if isinstance(casted_key, slice) or ( 3808 isinstance(casted_key, abc.Iterable) 3809 and any(isinstance(x, slice) for x in casted_key) 3810 ): 3811 raise InvalidIndexError(key) -> 3812 raise KeyError(key) from err 3813 except TypeError: 3814 # If we have a listlike key, _check_indexing_error will raise 3815 # InvalidIndexError. Otherwise we fall through and re-raise 3816 # the TypeError. 3817 self._check_indexing_error(key)
KeyError: 'Earnings Date'
Bad data proof
No response
yfinance
versionyfinance-0.2.50
Python version
3.11
Operating system
MacOSX Sequoia 15.1