ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

Issue with get_growth_estimates() indexing #2137

Closed mrizzben closed 2 days ago

mrizzben commented 3 days ago

Describe bug

ticker.get_growth_estimates() or ticker.growth_estimates throws a value error on indexing when called

Simple code that reproduces your problem

ticker =yf.Ticker("AAPL")
ticker.get_growth_estimates(as_dict=True)

Debug log

DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG params={'modules': 'earningsTrend', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'AAPL'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG reusing cookie DEBUG reusing crumb DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting _make_request() DEBUG Exiting get() DEBUG get_raw_json(): https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG Entering get() DEBUG Entering _make_request() DEBUG url=https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL DEBUG params={'modules': 'industryTrend,sectorTrend,indexTrend', 'corsDomain': 'finance.yahoo.com', 'formatted': 'false', 'symbol': 'AAPL'} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = 'basic' DEBUG Entering _get_cookie_and_crumb_basic() DEBUG reusing cookie DEBUG reusing crumb DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=200 DEBUG Exiting _make_request() DEBUG Exiting get()**


ValueError Traceback (most recent call last) Cell In[6], line 2 1 ticker =yf.Ticker("AAPL") ----> 2 ticker.get_growth_estimates(as_dict=True)

File ~\AppData\Roaming\Python\Python311\site-packages\yfinance\base.py:308, in TickerBase.get_growth_estimates(self, proxy, as_dict) 303 """ 304 Index: 0q +1q 0y +1y +5y -5y 305 Columns: stock industry sector index 306 """ 307 self._analysis.proxy = proxy or self.proxy --> 308 data = self._analysis.growth_estimates 309 return data.to_dict() if as_dict else data

File ~\AppData\Roaming\Python\Python311\site-packages\yfinance\scrapers\analysis.py:240, in Analysis.growth_estimates(self) 237 data_dict[period].append(item.get('growth', None)) 239 cols = ['stock', 'industry', 'sector', 'index'] --> 240 self._growth_estimates = pd.DataFrame(data_dict, index=cols).T 241 return self._growth_estimates

File c:\Users\usr\miniconda3\envs\project\Lib\site-packages\pandas\core\frame.py:778, in DataFrame.init(self, data, index, columns, dtype, copy) 772 mgr = self._init_mgr( 773 data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy 774 ) 776 elif isinstance(data, dict): 777 # GH#38939 de facto copy defaults to False only in non-dict cases --> 778 mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager) 779 elif isinstance(data, ma.MaskedArray): 780 from numpy.ma import mrecords

File c:\Users\usr\miniconda3\envs\project\Lib\site-packages\pandas\core\internals\construction.py:503, in dict_to_mgr(data, index, columns, dtype, typ, copy) 499 else: 500 # dtype check to exclude e.g. range objects, scalars 501 arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays] --> 503 return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)

File c:\Users\usr\miniconda3\envs\project\Lib\site-packages\pandas\core\internals\construction.py:119, in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate) 116 index = ensure_index(index) 118 # don't force copy because getting jammed in an ndarray anyway --> 119 arrays, refs = _homogenize(arrays, index, dtype) 120 # _homogenize ensures 121 # - all(len(x) == len(index) for x in arrays) 122 # - all(x.ndim == 1 for x in arrays) (...) 125 126 else: 127 index = ensure_index(index)

File c:\Users\usr\miniconda3\envs\project\Lib\site-packages\pandas\core\internals\construction.py:630, in _homogenize(data, index, dtype) 627 val = lib.fast_multiget(val, oindex._values, default=np.nan) 629 val = sanitize_array(val, index, dtype=dtype, copy=False) --> 630 com.require_length_match(val, index) 631 refs.append(None) 633 homogenized.append(val)

File c:\Users\usr\miniconda3\envs\project\Lib\site-packages\pandas\core\common.py:573, in require_length_match(data, index) 569 """ 570 Check the length of data matches the length of the index. 571 """ 572 if len(data) != len(index): --> 573 raise ValueError( 574 "Length of values " 575 f"({len(data)}) " 576 "does not match length of index " 577 f"({len(index)})" 578 )

ValueError: Length of values (3) does not match length of index (4)

Bad data proof

No response

yfinance version

0.2.49

Python version

3.11

Operating system

Windows

ValueRaider commented 2 days ago

Is this fixed in latest main branch?

mrizzben commented 2 days ago

yup, fixed in latest update image