fuzzywuzzy icon indicating copy to clipboard operation
fuzzywuzzy copied to clipboard

fuzzywuzzy returns 0 instead of 100 in many corner cases

Open rralf opened this issue 7 years ago • 9 comments

Hi,

following issue(s) can be reproduced with python-levenshtein 0.12.0 and fuzzywuzzy 0.16.0

There are several combinations that should be considered similar while being scored as absolutely dissimilar.

fuzz.ratio('', '') evaluates to 0. Two empty absolutely identical, so this should be 100.

fuzz.ratio('{', '{') evaluates to 100, while fuzz.token_sort_ratio(['{'], ['{']) evaluates erroneously to 0. Inconsistently, fuzz.token_sort_ratio(['{a'], ['{a']) evaluates to 100. (which is correct IMO).

Proposal: Independent of the method, fuzzywuzzy should always return 100 if both arguments are absolutely equal. I think this could efficiently be checked.

Thanks!

rralf avatar Mar 21 '18 14:03 rralf

Pull requests - with the accompanying tests - are welcome and encouraged :)

josegonzalez avatar Mar 21 '18 16:03 josegonzalez

First I'd like to discuss those issues, I didn't have a look into the code yet. Additionally I still have to check if this behaviour depends on python-levenshtein (which I'm using) or not.

Maybe there's even some rationale behind this and the behaviour is intended for some reason.

Or in other words: Am I facing a bug or does it work as intended? :-)

rralf avatar Mar 21 '18 16:03 rralf

From my perspective, the tests pass, so any behavior is expected. If you can add this functionality and tests continue to pass, great!

One thing to note is that the ratio may be misleading if the tokens are all the same but actually mis-ordered. That might have actual implications on someone's code, but if we're not testing for that now, its fine to break imo.

josegonzalez avatar Mar 21 '18 16:03 josegonzalez

I'm currently writing some patches.

Think I will have to touch the check_for_none and check_empty_string decorators... Let me return with a pull request in a couple of hours.

rralf avatar Mar 22 '18 11:03 rralf

Please be sure to include perf benchmarks :)

josegonzalez avatar Mar 22 '18 12:03 josegonzalez

Hi,

before requesting to pull, here are the fixes.

How can I run performance benchmarks?

Thanks

rralf avatar Mar 22 '18 15:03 rralf

@rralf I looked over those changes and can assure @josegonzalez that they are performant. @josegonzalez do you actually need a perf tests here? This changeset looks good to me.

zackkitzmiller avatar Mar 22 '18 16:03 zackkitzmiller

Sounds fine with me. PR it.

josegonzalez avatar Mar 22 '18 16:03 josegonzalez

Huh, that went quickly... Thanks for reviewing.

rralf avatar Mar 22 '18 16:03 rralf