yfinance
yfinance copied to clipboard
Second execution of `.earnings_history` gives error because code doesn't use `is not None`
This code gives error when earnings_history
is executed second time
import yfinance
item = yfinance.Ticker('HD')
print(item.earnings_history) # OK
print(item.earnings_history) # ERROR
Traceback (most recent call last):
File "/home/furas/Pulpit/PYTHON - SO/2022.08.20 - yfinance - ipdb/main.py", line 20, in <module>
print(yahoo_stock_obj.earnings_history)
File "/usr/local/lib/python3.10/dist-packages/yfinance/ticker.py", line 217, in earnings_history
return self.get_earnings_history()
File "/usr/local/lib/python3.10/dist-packages/yfinance/base.py", line 901, in get_earnings_history
if self._earnings_history:
File "/usr/local/lib/python3.10/dist-packages/pandas/core/generic.py", line 1527, in __nonzero__
raise ValueError(
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I think all problem is in function get_earnings_history()
in line
https://github.com/ranaroussi/yfinance/blob/main/yfinance/base.py#L901
because it doesn't use is not None
to check it
if self._earnings_history is not None:
Similar line https://github.com/ranaroussi/yfinance/blob/main/yfinance/base.py#L820 in function get_earnings_history()
has is not None
BTW:
I found this problem when I tried to resolve problem on Stackoverflow:
python - how to access and manipulate rows from pandas dataframe in yahoo finance api - Stack Overflow
earnings_history
is fundamentally broken, should never have been merged into main. Use Ticker.earnings_dates
instead.