From d2b4b20f60f66d7ac15a759e1ae25fe94d300fc6 Mon Sep 17 00:00:00 2001 From: Kotesh Kumar Yelamati Date: Thu, 2 Jul 2026 12:37:44 -0400 Subject: [PATCH] fix: guard against empty extractBests result in dedupe() to avoid ValueError Add handling for cases with no matches in deduplication. --- thefuzz/process.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thefuzz/process.py b/thefuzz/process.py index fcf7e1e..600a8af 100644 --- a/thefuzz/process.py +++ b/thefuzz/process.py @@ -438,6 +438,9 @@ def dedupe( deduped = set() for item in contains_dupes: matches = extractBests(item, contains_dupes, scorer=scorer, score_cutoff=threshold, limit=None) - deduped.add(max(matches, key=lambda x: (len(x[0]), x[0]))[0]) + if matches: + deduped.add(max(matches, key=lambda x: (len(x[0]), x[0]))[0]) + else: + deduped.add(item) return list(deduped) if len(deduped) != len(contains_dupes) else contains_dupes