From 10010ffb9b4894b991087a63dc492ece016b476a Mon Sep 17 00:00:00 2001 From: Dan O'Huiginn Date: Tue, 17 Nov 2026 13:34:13 +0100 Subject: [PATCH] geo: a missing jurisdiction name reads as empty, not a crash pandas keeps a missing value missing through astype(str), so a null name reached maybe_repair_mojibake as a float. Some World Bank admin-2 districts have no name, so ingesting admin 2 failed. --- jdluc/__tests__/geo_test.py | 10 +++++++++- jdluc/geo.py | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jdluc/__tests__/geo_test.py b/jdluc/__tests__/geo_test.py index a59ad0e..670007f 100644 --- a/jdluc/__tests__/geo_test.py +++ b/jdluc/__tests__/geo_test.py @@ -436,7 +436,7 @@ def test_downscale_darray_respects_source_nodata(nodata: float) -> None: def get_dissolved_names( - records: list[tuple[str, str, float]], tmp_path: pathlib.Path + records: list[tuple[str, str | None, float]], tmp_path: pathlib.Path ) -> dict[str, str]: """`convert_vector_to_flatgeobuf` over one box per (id, name, side length).""" import geopandas @@ -498,3 +498,11 @@ def test_convert_vector_to_flatgeobuf_repairs_only_mojibake( assert get_dissolved_names(records=[("AAA", stored, 1.0)], tmp_path=tmp_path) == { "AAA": expected } + + +def test_convert_vector_to_flatgeobuf_reads_a_missing_name_as_empty( + tmp_path: pathlib.Path, +) -> None: + assert get_dissolved_names(records=[("AAA", None, 1.0)], tmp_path=tmp_path) == { + "AAA": "" + } diff --git a/jdluc/geo.py b/jdluc/geo.py index 4696a30..417ae66 100644 --- a/jdluc/geo.py +++ b/jdluc/geo.py @@ -105,7 +105,10 @@ def maybe_repair_mojibake(name: str) -> str: crs=gdf.crs, data={ "id": gdf[list(id_column_names)].astype(str).agg(" | ".join, axis=1), + # NB: pandas keeps a missing name missing through `astype(str)`, and some + # admin-2 districts have none "name": gdf[list(name_column_names)] + .fillna("") .astype(str) .map(maybe_repair_mojibake) .agg(" | ".join, axis=1),