diff --git a/datatypes/epc/domain/historic_epc_matching.py b/datatypes/epc/domain/historic_epc_matching.py index d31c918fd..09da3bf9a 100644 --- a/datatypes/epc/domain/historic_epc_matching.py +++ b/datatypes/epc/domain/historic_epc_matching.py @@ -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: