Skip to content

fix: guard dedupe() against empty extractBests result when processor empties the query - #96

Open
koteshyelamati wants to merge 1 commit into
seatgeek:masterfrom
koteshyelamati:patch-1
Open

fix: guard dedupe() against empty extractBests result when processor empties the query#96
koteshyelamati wants to merge 1 commit into
seatgeek:masterfrom
koteshyelamati:patch-1

Conversation

@koteshyelamati

Copy link
Copy Markdown

Fixes #94

Problem

dedupe() crashes with ValueError: max() arg is an empty sequence when any item in the input list is reduced to an empty string by the default processor (utils.full_process).

from thefuzz.process import dedupe
dedupe(['###', 'apple', 'apple pie'])
# ValueError: max() arg is an empty sequence

When full_process('###') returns '', every comparison scores 0, so extractBests returns [] (below the 70 threshold). The subsequent max([]) then raises ValueError.

Fix

Guard the max() call: if matches is empty, add item itself to deduped (treating it as its own cluster):

if matches:
    deduped.add(max(matches, key=lambda x: (len(x[0]), x[0]))[0])
else:
    deduped.add(item)

This preserves the existing warning (already emitted by extractBests) and keeps items that cannot be fuzzy-matched as their own entry in the deduplicated output.

…ueError

Add handling for cases with no matches in deduplication.
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

Successfully merging this pull request may close these issues.

dedupe() crashes with max() empty when an item reduces to an empty string under the default processor

1 participant