-
Notifications
You must be signed in to change notification settings - Fork 13
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
OverflowError when raise_on_invalid=True #13
Comments
This is a good find! If this were written as an On the other hand, the algorithm being used to return an I think the bug is not in In [2]: import fastnumbers
In [3]: fastnumbers.fast_float("03e106196")
Out[3]: inf
In [4]: fastnumbers.fast_real("03e106196")
Out[4]: '03e106196'
In [5]: fastnumbers.fast_real("03e106196", coerce=False)
Out[5]: inf
In [6]: fastnumbers.fast_real("03e106196", raise_on_invalid=True, coerce=False)
Out[6]: inf
In [7]: fastnumbers.fast_real("03e106196", raise_on_invalid=True)
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
<ipython-input-7-64eb4b6453ff> in <module>()
----> 1 fastnumbers.fast_real("03e106196", raise_on_invalid=True)
OverflowError: cannot convert float infinity to integer
In [8]: fastnumbers.__version__
Out[8]: '2.0.4' If The correct thing to do would be to detect if |
In your opinion, what should be the correct behavior? >>> fastnumbers.fast_real("03e106196") == inf # coerce=True or >>> fastnumbers.fast_real("03e106196") == 3 * 10**106196 # coerce=True I would expect the same result whether |
oh, good question. Python says "inf" for the literal |
Minimum, Complete, Verifiable Example
Error message, Traceback, Desired behavior, Suggestion, Request, or Question
I would expect a
ValueError
as it's not a valid float. However, instead there's anOverflowError
.It looks like this is because
string_contains_intlike_float
returns true for this value, but isn't aware about the exponent being really big.The text was updated successfully, but these errors were encountered: