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

added cleanup for number_convert to address errors #122

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

fastflair
Copy link
Contributor

Description

The Insider.get_insider function is failing in util.py with this error:
File "h:\anaconda3\lib\site-packages\finvizfinance\insider.py", line 88, in get_insider
info_dict[table_header[i]] = number_covert(col.text)
File "h:\anaconda3\lib\site-packages\finvizfinance\util.py", line 148, in number_covert
elif num[-1] == "%":
IndexError: string index out of range

Type of change

  • Bug fix (non-breaking change which fixes an issue)

What you did

Changes Made:

  • Empty String Check (if not num): This ensures that the code doesn't attempt to access num[-1] if num is empty.
  • Stripping Whitespace (num = num.strip()): Removes any leading or trailing whitespace in the string, ensuring clean input.
  • Replaced .split(",") with .replace(",", ""): This simplifies removing commas from the string, making it more efficient.

How This Fixes the Problem:
The if not num check ensures that the function won't try to access the last character of an empty string, thus avoiding the IndexError.
If num is "%", "B", "M", or "K", the function properly processes the string and converts it to the corresponding float.
If num is just a plain number with commas, it will remove the commas and convert the number to a float.

@lit26 lit26 merged commit 33fe701 into lit26:master Oct 3, 2024
1 check passed
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.

2 participants