Answer architecture round 3: fence's docstring says a locality needs entries in both child maps, and zcta_localities says what it maps to

This commit is contained in:
2026-10-09 12:26:00 +02:00
committed by Lillem4n
parent c032cb779c
commit 32e01565b4
3 changed files with 14 additions and 14 deletions
+9 -9
View File
@@ -73,12 +73,12 @@ def top_streets(count, per_locality, column):
def fence(regions, municipalities, localities, streets, postal_codes):
"""Meet the loader's fence that every parent row has a child row: keep each locality both streets and postal_codes
hold a key for, then each municipality and region left with a child. regions and municipalities map a code to a
row, and a municipality row names its region under "region". localities map a key to a locality row: name,
municipality, population, lat and lon, besides the columns its country adds. streets and postal_codes map a locality's
key to its rows. Returns the kept rows, then the dropped rows, each a dict keyed by table: "locality", "municipality"
and "region"."""
"""Meet the loader's fence that every parent row has a child row: keep each locality that has entries in both
streets and postal_codes, each a map from a locality's key to its entries, then each municipality and region left
with a child. regions and municipalities map a code to a row, and a municipality row names its region under
"region". localities map a key to a locality row: name, municipality, population, lat and lon, besides the columns
its country adds. Returns the kept rows, then the dropped rows, each a dict keyed by table: "locality",
"municipality" and "region"."""
kept = {"locality": {k: l for k, l in localities.items() if streets.get(k) and postal_codes.get(k)}}
municipality_codes = {l["municipality"] for l in kept["locality"].values()}
kept["municipality"] = {c: m for c, m in municipalities.items() if c in municipality_codes}
@@ -89,8 +89,8 @@ def fence(regions, municipalities, localities, streets, postal_codes):
return kept, dropped
def log_dropped(rows, why):
"""Logs each row as dropped for why, by its key and its name where the two differ."""
def log_dropped_localities(rows):
"""Logs each locality row as dropped, by its key and its name where the two differ."""
for key, row in rows.items():
label = key if key == row["name"] else f"{key} {row['name']}"
print(f"{label}: {why}, dropped", file=sys.stderr)
print(f"{label}: no street or postal code, dropped", file=sys.stderr)