Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geocodio #468

Merged
merged 9 commits into from Mar 27, 2021
Merged

Add geocodio #468

merged 9 commits into from Mar 27, 2021

Conversation

duckontheweb
Copy link
Contributor

Adds geocoder class for Geocod.io API.

The API returns a 422 status code for invalid queries. This PR handles these using the _geocoder_exception_handler method, but it might be reasonable to map this code to a GeocoderQueryError in geopy.geocoders.base.ERROR_CODE_MAP.

#465

@duckontheweb
Copy link
Contributor Author

@KostyaEsmukov Any feedback on this PR or thoughts on when it might be merged? Thanks!

@KostyaEsmukov KostyaEsmukov added this to the 2.2 milestone Mar 20, 2021
Copy link
Member

@KostyaEsmukov KostyaEsmukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for the late response.

Overall looks good, I left a couple of minor comments.

The API returns a 422 status code for invalid queries. This PR handles these using the _geocoder_exception_handler method, but it might be reasonable to map this code to a GeocoderQueryError in geopy.geocoders.base.ERROR_CODE_MAP.

I guess it won't break anything if we move the 422 error to the ERROR_CODE_MAP. However, keeping that in the geocoder's own _geocoder_exception_handler method has a benefit of being more explicit, and it will protect against possibility of future refactorings breaking that error processing for Geocodio.

Pick whatever you like the most, I'm okay with both options.

geopy/geocoders/geocodio.py Outdated Show resolved Hide resolved
if street is not None and \
not any(p is not None for p in (city, state, postal_code)):
raise GeocoderQueryError('If street is provided must also provide city, '
'state, and/or postal_code.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why these conditions must be checked on the client-side?

(I'm okay with keeping these unless they might change in future).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only argument would be to save making an invalid request, which might count against rate limits or account request limits.

geopy/geocoders/geocodio.py Outdated Show resolved Hide resolved
test/geocoders/geocodio.py Outdated Show resolved Hide resolved
@duckontheweb
Copy link
Contributor Author

The API returns a 422 status code for invalid queries. This PR handles these using the _geocoder_exception_handler method, but it might be reasonable to map this code to a GeocoderQueryError in geopy.geocoders.base.ERROR_CODE_MAP.

I guess it won't break anything if we move the 422 error to the ERROR_CODE_MAP. However, keeping that in the geocoder's own _geocoder_exception_handler method has a benefit of being more explicit, and it will protect against possibility of future refactorings breaking that error processing for Geocodio.

Pick whatever you like the most, I'm okay with both options.

Okay, I'm a fan of being explicit, so I'll just stick with handling it in the _geocodoer_exception_handler.

Copy link
Member

@KostyaEsmukov KostyaEsmukov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@KostyaEsmukov KostyaEsmukov merged commit 00c13d3 into geopy:master Mar 27, 2021
@KostyaEsmukov KostyaEsmukov mentioned this pull request Mar 27, 2021
KostyaEsmukov added a commit that referenced this pull request Mar 27, 2021
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.

None yet

2 participants