Skip to content

Make RapidFuzzMatcher the default AdminLevel matcher - #92

Merged
mcarans merged 1 commit into
mainfrom
rapidfuzz-matcher
Sep 29, 2026
Merged

mcarans merged 1 commit into
mainfrom
rapidfuzz-matcher

Conversation

@mcarans

@mcarans mcarans commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Follows hdx-python-utilities#62, released in HDX Python Utilities 4.2.0.

  • Default matcher: AdminLevel fuzzy matches with RapidFuzzMatcher(RapidFuzzMatcher.place_name_scorer) instead of Phonetics. A new matcher parameter takes any matcher, eg. AdminLevel(config, matcher=Phonetics()) for the previous behaviour.
  • Names made of parts: before fuzzy matching, fuzzy_pcode calls resolve_name_parts.
    • A part that is the parent's name is dropped: "Falcón, Acosta" with parent VE11 gives VE1101 (logged as a "parts" match).
    • Lists of names ("Kampot & Kep", "Kutum, Tawila, Kornoi") are not fuzzy matched and are logged as ignored.
    • Parent names come from the parent-level rows passed to setup_from_iterable (parent_pcode_to_name).
  • Blank parent: fuzzy_pcode now treats parent="" as no parent, as get_pcode already did. Before, it returned None, so names passed with parent="" were never fuzzy matched. hdx-python-pipelineutils' complete_admins passes "" for admin2 when no admin1 code is known, so IPC and HNO admin2 names are now fuzzy matched.
  • Tests:
    • test_adminlevel_parent used "Kenge city"-style names to test replacement scoping. They relied on Phonetics failing to match "Kenge city" to "Kenge", so they are now garbled with "qx", which only the scoped "qx": "" replacements can resolve.
    • New tests: test_adminlevel_custom_matcher and test_adminlevel_list_of_names.
  • Docs and dependencies: a breaking change note and new Administration Level sections in documentation/index.md. The example's removed setup_from_admin_info is replaced with setup_from_iterable. Requires hdx-python-utilities>=4.2.0.

Impact

Results change for AdminLevel.get_pcode callers that fuzzy match. In a comparison over admin names collected from these repos:

  • Accuracy: on 2,762 names with an answer independent of either matcher, RapidFuzzMatcher gets 2,703 right against Phonetics' 2,696, with 35 wrong p-codes against 36.
  • Venezuela: part resolution resolves ~300 VEN "State, Municipality" names exactly.
  • Blank-parent fix: it sends ~90 more IPC admin2 names to the matcher. Some get wrong p-codes where before they had none (eg. CAF "Kémo" → Kabo with Phonetics). IPC may want fuzzy_match=False for admin2, or admin_fuzzy_dont entries.
  • Known RapidFuzzMatcher limits:
    • A name with one extra word still matches its shorter version, eg. IDN "North Maluku" → Maluku. OPHI would need admin_name_mappings for its 21 English-named Indonesian provinces.
    • COL "Municipality (Department)" names with no parent go to the bare municipality.

The "From 4.2.0" in the breaking change note assumes this is released as 4.2.0.

Testing

uv run pytest: 36 passed, against HDX Python Utilities 4.2.0 from PyPI.

AdminLevel fuzzy matches with HDX Python Utilities' RapidFuzzMatcher and
its place_name_scorer by default, and takes a matcher parameter so
Phonetics can still be used.

Before fuzzy matching, names made of parts are resolved with
resolve_name_parts: a part that is the parent's name is dropped (eg.
"Falcón, Acosta" with parent Falcón gives Acosta), and lists of names
(eg. "Kampot & Kep") are not fuzzy matched. Parent names are read from
the parent-level rows passed to setup_from_iterable.

Fuzzy matching is now tried when parent is "" as well as None, as
get_pcode already treated "" as no parent.

test_adminlevel_parent's "city" names are replaced with names garbled
with "qx", so the tests check replacement scoping rather than relying on
Phonetics failing to match "Kenge city" to "Kenge".

Requires HDX Python Utilities >= 4.2.0.
@github-actions

Copy link
Copy Markdown

Test Results

36 tests  +2   36 ✅ +2   1m 4s ⏱️ -15s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 1956421. ± Comparison against base commit ee17576.

@github-actions

Copy link
Copy Markdown

Test Results

36 tests  +2   36 ✅ +2   1m 22s ⏱️ +3s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 1956421. ± Comparison against base commit ee17576.

@mcarans
mcarans merged commit 3340935 into main Sep 29, 2026
3 of 4 checks passed
@coveralls

coveralls commented Sep 29, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 95.769% (-0.04%) from 95.807% — rapidfuzz-matcher into main

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.

2 participants