Skip to content

Commit

Permalink
account for force_ascii
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Aug 29, 2023
1 parent 681abb2 commit 504c037
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test_thefuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ def testWithProcessor(self):
best = process.extractOne(query, events, processor=lambda event: event[0])
self.assertEqual(best[0], events[0])

def testIssue57(self):
"""
account for force_ascii
"""
query = str(("test", "test"))
choices = [("test", "test")]
assert process.extract(query, choices)[0][1] == 100

def testWithScorer(self):
choices = [
"new york mets vs chicago cubs",
Expand Down
10 changes: 7 additions & 3 deletions thefuzz/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from rapidfuzz import fuzz as rfuzz
from rapidfuzz import process as rprocess
from functools import partial

_logger = logging.getLogger(__name__)

Expand All @@ -23,11 +24,14 @@ def _get_processor(processor, scorer):
fuzz.UWRatio, fuzz.UQRatio):
return processor

if not processor:
return utils.full_process
force_ascii = scorer not in [fuzz.UWRatio, fuzz.UQRatio]
pre_processor = partial(utils.full_process, force_ascii=force_ascii)

if not processor or processor == utils.full_process:
return pre_processor

def wrapper(s):
return utils.full_process(processor(s))
return pre_processor(processor(s))

return wrapper

Expand Down

0 comments on commit 504c037

Please sign in to comment.