diff --git a/backend/SearchEpc.py b/backend/SearchEpc.py index 0010191a..1ee1f950 100644 --- a/backend/SearchEpc.py +++ b/backend/SearchEpc.py @@ -702,6 +702,18 @@ class SearchEpc: exclude_old=exclude_old ) + # Check if it's a new build EPC. A property that doesn't have an EPC is not going to be a new build + # so we avoid comparing it to new builds + # TODO - this is experimental + newer_age_bands = [ + "England and Wales: 1996-2002", "England and Wales: 2003-2006", "England and Wales: 2007-2011", + "England and Wales: 2012 onwards" + ] + + if (~epc_data["construction-age-band"].isin(newer_age_bands)).sum(): + # We have some older age bands, so we need to filter them out + epc_data = epc_data[~epc_data["construction-age-band"].isin(newer_age_bands)].copy() + # If we have missing lodgment date, we fill it with inspection-date epc_data["lodgement-datetime"] = epc_data["lodgement-datetime"].fillna(epc_data["inspection-date"]) # If we still have missing dates, we set it to the mean of the non NA dates