pycountry icon indicating copy to clipboard operation
pycountry copied to clipboard

Maryland is not found in subdivisions as a US state

Open jamesshieh opened this issue 5 years ago • 1 comments

Testing a lookup for "Maryland" In [3]: pycountry.subdivisions.lookup('Maryland')
Out[3]: Subdivision(code='LR-MY', country_code='LR', name='Maryland', parent_code=None, type='County')

It does show up under US-MD In [7]: pycountry.subdivisions.lookup('US-MD')
Out[7]: Subdivision(code='US-MD', country_code='US', name='Maryland', parent_code=None, type='State')

jamesshieh avatar Dec 14 '20 23:12 jamesshieh

I ran into the same issue here, for the ambiguous subdivisions pycountry finds the first one and returns. If you want to find a subdivision within a particular country you could do something like {subdiv.name.lower(): subdiv for subdiv in pycountry.subdivisions.get(country_code='US')}, and then you have a mapping for subdivisions within a country.

mmaroli avatar Dec 18 '20 00:12 mmaroli

@jamesshieh @mmaroli is correct you can also use our newly implement search_fuzzy method in main thanks to #175

pycountry.subdivisions.search_fuzzy('Maryland')
[SubdivisionHierarchy(code='LR-MY', country_code='LR', name='Maryland', parent_code=None, type='County'), SubdivisionHierarchy(code='US-MD', country_code='US', name='Maryland', parent_code=None, type='State')]

nschimmoller avatar Dec 11 '23 17:12 nschimmoller