Skip to content

Commit

Permalink
Geocodio: add limit=1 for exactly_one=True (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaEsmukov committed Mar 27, 2021
1 parent cd1f8eb commit 9fd5fd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions geopy/geocoders/geocodio.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def geocode(
raise GeocoderQueryError('If street is provided must also provide city, '
'state, and/or postal_code.')

api = '%s://%s%s' % (self.scheme, self.domain, self.geocode_path)
if exactly_one:
limit = 1

params = dict(
api_key=self.api_key,
Expand All @@ -146,6 +147,7 @@ def geocode(
k: v for k, v in params.items() if v is not None
}

api = '%s://%s%s' % (self.scheme, self.domain, self.geocode_path)
url = "?".join((api, urlencode(params)))

logger.debug("%s.geocode: %s", self.__class__.__name__, url)
Expand Down Expand Up @@ -183,11 +185,12 @@ def reverse(
'q': self._coerce_point_to_string(query),
'api_key': self.api_key
}
if exactly_one:
limit = 1
if limit is not None:
params['limit'] = limit

api = '%s://%s%s' % (self.scheme, self.domain, self.reverse_path)

url = "?".join((api, urlencode(params)))

logger.debug("%s.reverse: %s", self.__class__.__name__, url)
Expand Down
7 changes: 7 additions & 0 deletions test/geocoders/geocodio.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ async def test_zero_results(self):
assert str(excinfo.value) == 'Could not geocode address. ' \
'Postal code or city required.'

async def test_geocode_many_results(self):
result = await self.geocode_run(
{"query": "Springfield", "exactly_one": False},
{}
)
assert len(result) > 1

async def test_reverse(self):
location = await self.reverse_run(
{"query": Point(40.75376406311989, -73.98489005863667)},
Expand Down

0 comments on commit 9fd5fd5

Please sign in to comment.