Model/domain/addresses/postcode_batching.py
Khalim Conn-Kowlessar cc4bf4394e Both postcode batchers share one group-preserving packing core 🟪
Review feedback (#1481): the address batcher and the Modelling Run batcher
implemented the same greedy packing; the core moves to
utilities/grouped_batching.py and both become thin wrappers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 13:24:02 +00:00

17 lines
536 B
Python

from __future__ import annotations
from collections.abc import Iterable, Iterator
from domain.addresses.unstandardised_address import AddressList, UnstandardisedAddress
from utilities.grouped_batching import iter_grouped_batches
def iter_postcode_grouped_batches(
addresses: Iterable[UnstandardisedAddress],
*,
max_batch_size: int = 500,
) -> Iterator[AddressList]:
for batch in iter_grouped_batches(
addresses, key=lambda a: a.postcode, max_batch_size=max_batch_size
):
yield AddressList(batch)