Rank historic EPC records by address similarity 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-06-29 14:50:03 +00:00
parent d41eb84530
commit d084a0a785

View file

@ -66,7 +66,31 @@ def rank_historic_epc(
"""Score ``records`` against ``user_address`` (best first), keeping every
record including hard-zero non-matches. The pure scoring half of the
historic-EPC lookup: no I/O, so it is unit-testable without S3."""
raise NotImplementedError
if not user_address:
raise ValueError("user_address must be non-empty")
if not records:
return []
df = pd.DataFrame(
{
address_column: [r.address for r in records],
uprn_column: [r.uprn for r in records],
}
)
scored = rank_address_similarity(
df,
user_address=user_address,
address_column=address_column,
uprn_column=uprn_column,
)
return [
ScoredHistoricEpc(
record=records[i],
lexiscore=float(row["lexiscore"]),
lexirank=int(row["lexirank"]),
)
for i, row in scored.iterrows()
]
def _sanitise_postcode(postcode: str) -> str: