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

Proposal: change behavior of isfloat function with respect to treatment of strings containing integers #39

Closed
SethMMorton opened this issue May 27, 2020 · 3 comments

Comments

@SethMMorton
Copy link
Owner

Describe the feature or enhancement
The proposal is to change how isfloat interprets strings. Currently, it has the following behavior:

>>> isfloat("56")
True
>>> isfloat("56.0")
True
>>> isfloat(56)
False
>>> isfloat(56.0)
True

The proposal is to change the behavior to the following:

>>> isfloat("56")
False
>>> isfloat("56.0")
True
>>> isfloat(56)
False
>>> isfloat(56.0)
True

Provide a concrete example of how the feature or enhancement will improve fastnumbers
isfloat is inconsistent. For strings that look like integers, it returns True, but for numeric types it is strict. In fact, isfloat behaves identically to isreal for string input. Users wanting to detect if string input is actually a float an not an int cannot in a single call.

The rational behind this was that for string input, isfloat would return True if fast_float would successfully convert to a float. The intention was to introduce symmetry between the functions, but unfortunately this was not achieved because of how the function behaves with numeric input.

Really, the current behavior of isfloat is acting like isreal.

A successful introduction will have a deprecation schedule, so that users are not completely caught off-guard. At the very least, this needs to be advertised at the top of the README for a while.


NOTE: This was brought up as part of #37 by @argenisleon.

@SethMMorton SethMMorton changed the title Proposal: change behavior of isfloat function Proposal: change behavior of isfloat function with respect to treatment of strings containing integers May 29, 2020
@SethMMorton
Copy link
Owner Author

SethMMorton commented Jun 7, 2020

I have cleaned/moved up a conversation intended for #37.

Repository owner deleted a comment from argenisleon Jun 7, 2020
Repository owner deleted a comment from argenisleon Jun 7, 2020
@SethMMorton
Copy link
Owner Author

SethMMorton commented Jun 7, 2020

Below is a comment by @argenisleon originally from #37 that instigated this issue being created (original comment deleted).


Just this morning I had this problem. From the readme:

# Check that a string can be converted to a float
isfloat('56')
True
# Check if a given number is a float
....
isfloat(56)
False

The same function seems to check if a string can be converted to a float but at the same time an int is a float. I think the question it should answer is this string or number a float?
In both cases I think the answer should be False.

My point here is that as a user I am not sure what fastnumbers is trying to answer.

It is difficult for me as a new user to digest all the possible combinations of params of the current API and how it should work. I think we can map what the output should be in something like a minpmap https://miro.com/ and then go back to C and implement it.

What do you think?

@SethMMorton
Copy link
Owner Author

SethMMorton commented Jun 7, 2020

And here was my comment originally from #37 to the direct above (original comment deleted).


Yeah, this isn't clear.

Basically, for string input I had implemented it to return True if fast_float would have returned a float or not. But for numeric input I basically was checking the type. So it really behaves differently depending on the type.

Not cool.

This will probably require a backwards-incompatible change.

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

No branches or pull requests

1 participant