Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion jdluc/__tests__/geo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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": ""
}
3 changes: 3 additions & 0 deletions jdluc/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading