Repository navigation
Count countries with a lowercase code only once - #1574
Merged
Merged
Conversation
A few stations carry their country code in lowercase, like "de". The API lists those as a country of their own, so Germany showed up twice. Merge them into the uppercase code and add up their station counts; filtering on "DE" already includes those stations. Merging needs the whole list, so countries are now always fetched in full, and sorted and paged by the client. Country names also resolve for lowercase codes now.
This was referenced Oct 1, 2026
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.
Breaking change
None in practice.
Country.codeis now always uppercase, and a country no longer shows up twice. Sorting by station count is now done by the client instead of the API, with the same result, plus a stable alphabetical order for countries with the same count.Proposed change
Found while fixing the country sorting in #1568. A few stations carry their country code in lowercase. The API lists those codes as countries of their own, so after resolving the names,
countries()returned the same country twice:The set changes over time (right now
bg,de,it,trandus; earlier today alsonl), and filtering on a code is case-insensitive in the API:bycountrycodeexact/DEalready includes thedestation. So these belong to the same country.countries()now merges codes by their uppercase form and adds up the station counts. Doing that correctly needs the whole list, since a lowercase code could land on a different page than its uppercase sibling. The list is short (around 245 entries), so it is now always fetched in full, and sorted and paged by the client, for both supported orders.country_name()is also case-insensitive now (including the Kosovo special case), so a station with country codedegets "Germany" too.Live, after this change: 241 countries, no duplicate names, Germany with 6471 stations.
Type of change
Additional information
Checklist
poetry run pytestpasses locally. A pull request cannot be merged unless CI is green.poetry run prek run --all-filespasses (lint, format, and type checks).