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

BUG: Can't handle nan #41

Open
Zeroto521 opened this issue Nov 21, 2022 · 1 comment
Open

BUG: Can't handle nan #41

Zeroto521 opened this issue Nov 21, 2022 · 1 comment

Comments

@Zeroto521
Copy link

Zeroto521 commented Nov 21, 2022

Problem:

nan value is not None, so it will be skipped by check_for_none.
And nan is float and don't have len method, so check_empty_string raises an error.

>>> from thefuzz.fuzz import ratio
>>> ratio("a", float("nan"))  # or `np.nan`
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Zero\mambaforge\envs\dtoolkit-dev\lib\site-packages\thefuzz\utils.py", line 38, in decorator
    return func(*args, **kwargs)
  File "C:\Users\Zero\mambaforge\envs\dtoolkit-dev\lib\site-packages\thefuzz\utils.py", line 29, in decorator
    return func(*args, **kwargs)
  File "C:\Users\Zero\mambaforge\envs\dtoolkit-dev\lib\site-packages\thefuzz\utils.py", line 46, in decorator
    if len(args[0]) == 0 or len(args[1]) == 0:
TypeError: object of type 'float' has no len()

Solution:

check_for_none need to be updated.
or create a new decorator for handling nan value.

thefuzz/thefuzz/utils.py

Lines 33 to 39 in 6e68af8

def check_for_none(func):
@functools.wraps(func)
def decorator(*args, **kwargs):
if args[0] is None or args[1] is None:
return 0
return func(*args, **kwargs)
return decorator

@maxbachmann
Copy link
Contributor

Now that rapidfuzz is used under the hood, this is working

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

No branches or pull requests

2 participants