ranaroussi / yfinance

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

AAPL get_shares() does return nothing #932

Closed s-weissbach closed 2 years ago

s-weissbach commented 2 years ago

I've noticed, that the get_shares() method does not work for AAPL. It returns nothing (no errors).

import yfinance as yf

stock = yf.Ticker("AAPL")
stock.get_shares()

The information can be found on yahoo (https://finance.yahoo.com/quote/AAPL/financials?p=AAPL) When I try the command with TSLA, it works fine.

stock = yf.Ticker("TSLA")
stock.get_shares()

It returns:

      BasicShares
Year             
2018    852625000
2019    885000000
2020    933000000

as it can be found here (https://finance.yahoo.com/quote/TSLA/financials?p=TSLA) How can I fix this?

ProgrammingDao commented 2 years ago

Issue seems to be at TickerBase._get_fundamentals line 524 when trying to build a data frame from the loaded data['annualBasicAverageShares'] which is as follows:

[{'dataId': 29010, 'asOfDate': '2018-09-30', 'periodType': '12M', 'currencyCode': 'USD', 'reportedValue': 19821508000}, {'dataId': 29010, 'asOfDate': '2019-09-30', 'periodType': '12M', 'currencyCode': 'USD', 'reportedValue': 18471336000}, {'dataId': 29010, 'asOfDate': '2020-09-30', 'periodType': '12M', 'currencyCode': 'USD', 'reportedValue': 17352119000}, None]

The last element None is the one blocking the creation of the dataframe and thus the assignment to self._shares.

Could be fixed by removing the None element.