Repository navigation
A Custom Location in Kosovo builds, and the name "Kosovo" no longer means Serbia - #77
Open
HughRunyan wants to merge 2 commits into
Open
HughRunyan wants to merge 2 commits into
HughRunyan wants to merge 2 commits into
Conversation
…pycountry pycountry has no Kosovo. _iso3_for asked it first, so XKX, the code SWEET's defaults and WasteMAP's country list use, raised LookupError, and dst_baseline_blank and cityparams_obj_for_blank_site raised "Country 'XKX' not found." (WasteMAP's city tool answered 500). By name, the fuzzy search resolved "Kosovo" to Serbia, so sdst_prepopulate prefilled a point in Kosovo as Serbia. _iso3_for now tries region_lookup_iso3 by code, then country_to_iso3 by name, both ignoring case, before pycountry. The other 249 codes WasteMAP offers resolve as before, so their output is bit-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
A city DST Custom Location in Kosovo answers HTTP 500 on wastemap.earth, and the site tool's prefill for a point in Kosovo returns Serbia.
_iso3_for(incity_params.py) turns the caller's country into the ISO3 code SWEET's defaults are keyed by. It asked pycountry first, and pycountry has no Kosovo:LookupError, soCity.dst_baseline_blankandCity.cityparams_obj_for_blank_siteraisedValueError("Country 'XKX' not found.").defaults_2019.region_lookup_iso3["XKX"]is "Southern Europe", so SWEET had the defaults; only the lookup failed.search_fuzzy("Kosovo")returns Serbia, whose province Kosovo-Metohija matches.sdst_prepopulatenames the country with the geocoder's English name, so a point in Kosovo was prefilled, and then modelled, as Serbia. The same search resolves "Curacao" to the Netherlands, and finds nothing for Macau, Pitcairn Islands, Svalbard and Jan Mayen Islands, US Minor Islands, or French Southern and Antarctic Lands.Environment: prod API (api.wastemap.earth), SWEET_python main
d5c592e, pycountry 26.2.16.Reproduction (read-only GET):
curl -sG https://api.wastemap.earth/v1/city_emissions/city_baseline_parameters_v1_5 --data-urlencode "city_name=*" --data-urlencode country=XKX --data-urlencode population=2000000 --data-urlencode precipitation=500 --data-urlencode temperature=25Expected: a baseline, as for
country=PAK.Actual:
Internal Server Error(HTTP 500). Locally:City("*").dst_baseline_blank("XKX", 2_000_000, 500.0, 25.0)raisesValueError: Country 'XKX' not found.Fix
_iso3_fortries SWEET's own table first: by code (defaults_2019.region_lookup_iso3), then by name (defaults_2019.country_to_iso3), ignoring case as pycountry does. Anything else goes to pycountry as before, so the exact-before-fuzzy order that fixed "MUS" (#71) stands.Effect (model-output change for a country given by name)
Checked by running
dst_baseline_blankfor every code WasteMAP's/v1/dst_countriesoffers, before and after:ValueErrorKosovo has no country rows in SWEET's defaults, so it takes Southern Europe's regional ones. It does have its own UN population series, which it now grows with. Climate TRACE's pipeline is unaffected: only
dst_baseline_blank,cityparams_obj_for_blank_siteandsdst_prepopulatecall_iso3_for, and all three are WasteMAP paths.Tests
tests/test_country_lookup.py(14 of its 17 fail on main):dst_baseline_blank("XKX", 2_000_000, 500.0, 25.0)builds a city that grows with Kosovo's population.cityparams_obj_for_blank_site(country="XKX", …)builds.sdst_prepopulatefor a point in Pristina returnsXKX, notSRB. The geocoder and database are faked, so it runs offline.Full suite: 289 passed (Python 3.13 locally; CI runs 3.12).
Paired PR
RMI/WasteMAP#857, on the same branch name, so WasteMAP CI installs this branch. It makes both city DST endpoints answer 400 rather than 500 for a country SWEET can't find, and its fast tests run a Custom Location for every country the DST offers. Merge this one first.
Notes for review
XKXcan't be looked up, before or after", and counts 249 countries. If this merges first, those lines need updating when A Custom Location buries or dumps its waste in every country #74 is rebased; with both, Kosovo takes Southern Europe's regional disposal split.changelog/2026-10.mddoesn't exist on main. City DST scenarios run for São Paulo and Brasília: load_csv_new normalizes a city's composition #73, A Custom Location buries or dumps its waste in every country #74, Moving waste to a city's existing gas capture changes its emissions #75 and this PR each create it, so whichever merges second resolves a simple conflict.""→ GBR,"None"→ ITA). None of WasteMAP's frontends send those, so I've left it for a separate change.Acceptance criteria
City("*").dst_baseline_blank("XKX", 2_000_000, 500.0, 25.0)builds a city._iso3_forresolves every code and name in SWEET's own table to SWEET's code, Kosovo included.changelog/2026-10.md,changelog/README.md).Definition of Done
Acceptance criteria met · tests & checks pass · docs (changelog) updated · reviewed & merged.
🤖 Generated with Claude Code