Return empty list for a postcode with no historic EPC shard 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jun-te Kim 2026-06-29 14:46:42 +00:00
parent 6a095a2cf2
commit 88f4739ce8

View file

@ -3,6 +3,7 @@ from __future__ import annotations
from collections.abc import Callable
import pandas as pd
from botocore.exceptions import ClientError
from datatypes.epc.domain.historic_epc import HistoricEpc
from datatypes.epc.domain.historic_epc_matching import (
@ -35,5 +36,10 @@ class HistoricEpcS3Repository(HistoricEpcRepository):
pc = _sanitise_postcode(postcode)
bucket, root_prefix = parse_s3_uri(self._s3_root)
key = f"{root_prefix.rstrip('/')}/{pc}/data.csv.gz"
df = self._read_csv_gz(bucket, key)
try:
df = self._read_csv_gz(bucket, key)
except ClientError as e:
if e.response.get("Error", {}).get("Code") in ("NoSuchKey", "404"):
return []
raise
return [_map_historic_epc_pandas_row_to_domain(row) for _, row in df.iterrows()]