FuzzyWuzzy throwing `ValueError` when reading string array

Author: SkynetGamesCreated Oct 12, 2018Updated Oct 17, 2023

Hi,

A friend and I are using FuzzyWuzzy for approximate string matching (imagine that lol) to find a given input in an array that we generated out of a JSON (the steam API JSON to be specific).

Here is the code we are using to generate an array out of the JSON where path is the path to the JSON saved on the disk and array_location is just so we extract only the game IDs and game names.

def array_from_json_file(path, array_location):
	array = {}
	with open(path, encoding='utf-8') as f:
		array = json.load(f)
	array = enumerate_json(array, array_location)
	return array

And here is the code that iterates through the entire list for fuzzy matching, where query is the user input, data is the array we generated from the JSON, and str_location is so it is only searching the names instead of the IDs

def fuzzy_query(query, data, str_location):
	results = []
	for i in range(0, len(data)):
		target = enumerate_json(data[i], str_location)
		if (len(target) > 1):
			strength = fuzz.partial_ratio(query.lower(), target.lower()) # This is where the issue is
			results.append((strength, data[i]))
	return results

Finally, the Traceback that I get when I run the script

Traceback (most recent call last):
  File "main.py", line 81, in <module>
    main()
  File "main.py", line 73, in main
    query_results = fuzzy_query(query, games, ["name"])
  File "main.py", line 45, in fuzzy_query
    strength = fuzz.partial_ratio(query.lower(), target.lower())
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fuzzywuzzy\\\utils.py", line 38, in decorator
    return func(*args, **kwargs)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fuzzywuzzy\\\utils.py", line 29, in decorator
    return func(*args, **kwargs)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fuzzywuzzy\\\utils.py", line 47, in decorator
    return func(*args, **kwargs)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fuzzywuzzy\fuzz.py", line 47, in partial_ratio
    blocks = m.get_matching_blocks()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\fuzzywuzzy\StringMatcher.py", line 59, in get_matching_blocks
    self._str1, self._str2)
ValueError: apply_edit edit operations are invalid or inapplicable

My friend and I have the same versions in both Python version (v3.6.6) and FuzzyWuzzy version (v0.17.0). He's using Ubuntu, while I'm running Windows 10 LTSB. He has no issues running our script. As far as we can tell, there are no environment differences that would make this an issue.

Edit #1; I have completely removed the Python environment on my system and reinstalled it, no change. Issue still persists