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

Feature request: handle NaN #62

Closed
bersbersbers opened this issue Oct 5, 2022 · 3 comments · Fixed by #63
Closed

Feature request: handle NaN #62

bersbersbers opened this issue Oct 5, 2022 · 3 comments · Fixed by #63
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest help wanted Extra attention is needed

Comments

@bersbersbers
Copy link

bersbersbers commented Oct 5, 2022

What did you do?

import humanize, math
humanize.metric(math.nan)

What did you expect to happen?

"NaN"

What actually happened?

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\bers\.pyenv-win-venv\envs\project\lib\site-packages\humanize\number.py", line 519, in metric
exponent = int(math.floor(math.log10(abs(value)))) if value != 0 else 0
ValueError: cannot convert float NaN to integer

@bersbersbers
Copy link
Author

(For the record, I did not actually do humanize.metric(math.nan), I just happened to come across a NaN value.)

@hugovk hugovk added Hacktoberfest good first issue Good for newcomers help wanted Extra attention is needed bug Something isn't working labels Oct 5, 2022
@hugovk
Copy link
Member

hugovk commented Oct 5, 2022

Thanks for the report, PR welcome to fix it!

@The-Debarghya The-Debarghya mentioned this issue Oct 5, 2022
@bersbersbers
Copy link
Author

It would also make sense to handle this in one common location for +/-Inf and all other functions failing on NaN, such as humanize.scientific(math.nan) or humanize.fractional(math.nan).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants