Better merge
Some checks failed
CI / Check (push) Failing after 3m46s
Build and publish Docker image / build-and-push (push) Successful in 4m20s

This commit is contained in:
Andras Schmelczer 2026-06-19 08:56:03 +01:00
parent fdd7a5c763
commit 3dd5cde626
2 changed files with 128 additions and 23 deletions

View file

@ -1129,6 +1129,70 @@ def test_match_direct_epc_street_fallback_recovers_numbered_listing() -> None:
assert matches["_direct_epc_match_method"].to_list() == ["street"]
def test_match_direct_epc_street_fallback_nulls_year_on_mixed_era_street() -> None:
# A number-less listing is matched to the *street*, never the exact property.
# When the same-street certificates span construction eras (a Victorian house
# and 2007 infill here), no single year represents the unidentified property,
# so the street-representative construction year is nulled rather than letting
# a new-build inherit an 1890 build date (the Enderby Street, Greenwich bug).
# Other EPC facts stay as street-representative estimates.
matches = _match_direct_epc(
_listing_matches([{"_listing_match_address": "EXAMPLE ROAD BROMLEY"}]),
_direct_epc_candidates(
[
{
"_direct_epc_match_address": "8 EXAMPLE ROAD",
"_direct_epc_address": "8, Example Road",
"_direct_construction_age_band": 1890,
},
{
"_direct_epc_row": 1,
"_direct_epc_match_address": "15 EXAMPLE ROAD",
"_direct_epc_address": "15, Example Road",
"_direct_construction_age_band": 2007,
},
]
),
)
assert matches.height == 1
assert matches["_direct_epc_match_method"].to_list() == ["street"]
assert matches["_direct_construction_age_band"].to_list() == [None]
assert matches["_direct_is_construction_date_approximate"].to_list() == [None]
# Energy rating remains a street-representative estimate (only the year is
# categorically wrong on a mixed street; the rest stay best-effort).
assert matches["_direct_current_energy_rating"].to_list() == ["C"]
def test_match_direct_epc_street_fallback_keeps_year_on_uniform_street() -> None:
# When the street is era-homogeneous (one development), the
# street-representative construction year IS meaningful and is kept. Two
# adjacent EPC bands a few years apart count as uniform.
matches = _match_direct_epc(
_listing_matches([{"_listing_match_address": "EXAMPLE ROAD BROMLEY"}]),
_direct_epc_candidates(
[
{
"_direct_epc_match_address": "8 EXAMPLE ROAD",
"_direct_epc_address": "8, Example Road",
"_direct_construction_age_band": 2007,
},
{
"_direct_epc_row": 1,
"_direct_epc_match_address": "15 EXAMPLE ROAD",
"_direct_epc_address": "15, Example Road",
"_direct_construction_age_band": 2009,
},
]
),
)
assert matches.height == 1
assert matches["_direct_epc_match_method"].to_list() == ["street"]
assert matches["_direct_construction_age_band"].to_list() == [2007]
assert matches["_direct_is_construction_date_approximate"].to_list() == [1]
def test_match_direct_epc_street_fallback_rejects_town_only_address() -> None:
# A town-only listing address ("COULSDON SURREY") shares only the locality
# suffix that most street keys in the outcode carry; without a street-name