Skip to content

Conversation

jonasmalacofilho
Copy link
Contributor

@jonasmalacofilho jonasmalacofilho commented Jun 9, 2025

A binary search is used to find the city specified with -i/--city. Therefore, the cities array must be sorted according to the comparison function used in the binary search.

The currently used comparison function normalizes city names. In particular, all names are lowercased, which impacts their lexicographical order.

Because of this, the following example fails without this patch, even though "Rio de Janeiro" is in data/cities.csv.

$ astroterm -mi "Rio de Janeiro"
ERROR: Could not find city "Rio de Janeiro"

To fix it, use the normalized city names when sorting them in filter_cities.py. The normalization should match the one used at runtime. Then regenerate data/cities.csv with:

$ python scripts/filter_cities.py cities15000.txt  data/cities.csv 200000

(cities15000.txt downloaded today from: https://download.geonames.org/export/dump/cities15000.zip)

A binary search is used to find the city specified with -i/--city.
Therefore, the cities array must be sorted accordingly to the comparison
function used in the binary search.

The currently used comparison function normalizes city names. In
particular, all names are lowercased, which impacts their
lexicographical order.

Because of this, the following example fails without this patch, even
though "Rio de Janeiro" is in data/cities.csv.

    $ astroterm -mi "Rio de Janeiro"
    ERROR: Could not find city "Rio de Janeiro"

To fix it, use the normalized city names when sorting them in
filter_cities.py. The normalization should match the one used at
runtime. Then regenerate data/cities.csv with:

$ python scripts/filter_cities.py cities15000.txt  data/cities.csv 200000

(cities15000.txt downloaded today from: https://download.geonames.org/export/dump/cities15000.zip)
@da-luce
Copy link
Owner

da-luce commented Jul 14, 2025

Nice catch - thanks @jonasmalacofilho!

@da-luce da-luce merged commit be8e924 into da-luce:main Jul 14, 2025
14 checks passed
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

see 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants