Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty str to float conversion error fix #523

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Featuredutka
Copy link

@Featuredutka Featuredutka commented Feb 12, 2022

Fix for the issue

#511

After a couple of experiments I found out that the error was caused by python trying to convert an empty string to the float.

Sample terminal output for 'PG' stock:

0.41
0.41
0.41

Traceback (most recent call last):
  File "/Users/ash/Desktop/stonks/ui.py", line 107, in run
    main.main(self.progresslink)
  File "/Users/ash/Desktop/stonks/main.py", line 51, in main
    stock_info = investpy.stocks.get_stock_dividends(stock, country=country_data[countryiterator])
  File "/Users/ash/opt/anaconda3/lib/python3.9/site-packages/investpy/stocks.py", line 973, in get_stock_dividends
    dividend_value = float(element_.getnext().text_content())
ValueError: could not convert string to float: ''
Abort trap: 6

So, apparantely that blank line was causing all the problems, but not any more with the try/except wrap.

@Featuredutka
Copy link
Author

Featuredutka commented Feb 12, 2022

Some checks later I discovered that the problem is not completely gone. It appears there are some stocks with no provided information at all (like PFE or MRK on the screenshot) - not even an empty string. So the try/exception wrap won't work for those.

Console data output for each stock in list:
Screen Shot 2022-02-13 at 01 43 36

To fix that another try/except clause was added

Console output after fix:
Screen Shot 2022-02-13 at 02 04 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant