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

Update to geopy 0.99 #108

Merged
merged 11 commits into from
Jul 11, 2014
7 changes: 6 additions & 1 deletion doc/source/about.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
About
=====

Coming soon...
Known issues
------------

- The ``geopy`` API has changed significantly over recent versions.
``geopy 0.99`` is currently supported (though it is known to fail
with Python 3.2, it should work with other supported python
versions).

.. toctree::
:maxdepth: 2
Expand Down
4 changes: 2 additions & 2 deletions geopandas/geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def geocode(strings, provider='googlev3', **kwargs):

"""
import geopy
from geopy.geocoders.base import GeocoderResultError
from geopy.geocoders.base import GeocoderQueryError

if not isinstance(strings, pd.Series):
strings = pd.Series(strings)
Expand All @@ -81,7 +81,7 @@ def geocode(strings, provider='googlev3', **kwargs):
for i, s in iteritems(strings):
try:
results[i] = coder.geocode(s)
except (GeocoderResultError, ValueError):
except (GeocoderQueryError, ValueError):
results[i] = (None, None)
time.sleep(_throttle_time(provider))

Expand Down
2 changes: 1 addition & 1 deletion requirements.test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
psycopg2>=2.5.1
geopy==0.96.3
geopy==0.99
matplotlib>=1.2.1
descartes>=1.0
pytest-cov
Expand Down
20 changes: 16 additions & 4 deletions tests/test_geocode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import absolute_import

import sys

from fiona.crs import from_epsg
import pandas as pd
from shapely.geometry import Point
Expand All @@ -14,7 +16,10 @@ def _skip_if_no_geopy():
try:
import geopy
except ImportError:
raise nose.SkipTest("Geopy not installed. Skipping")
raise nose.SkipTest("Geopy not installed. Skipping tests.")
except SyntaxError:
raise nose.SkipTest("Geopy is known to be broken on Python 3.2. "
"Skipping tests.")

class TestGeocode(unittest.TestCase):
def setUp(self):
Expand All @@ -25,6 +30,7 @@ def setUp(self):
def test_prepare_result(self):
# Calls _prepare_result with sample results from the geocoder call
# loop
from geopandas.geocode import _prepare_geocode_result
p0 = Point(12.3, -45.6) # Treat these as lat/lon
p1 = Point(-23.4, 56.7)
d = {'a': ('address0', p0.coords[0]),
Expand All @@ -48,6 +54,7 @@ def test_prepare_result(self):
self.assertAlmostEqual(coords[1], test[0])

def test_prepare_result_none(self):
from geopandas.geocode import _prepare_geocode_result
p0 = Point(12.3, -45.6) # Treat these as lat/lon
d = {'a': ('address0', p0.coords[0]),
'b': (None, None)}
Expand All @@ -63,17 +70,22 @@ def test_prepare_result_none(self):
self.assert_(pd.np.isnan(row['address']))

def test_bad_provider(self):
from geopandas.geocode import geocode
with self.assertRaises(ValueError):
geocode(['cambridge, ma'], 'badprovider')

def test_googlev3(self):
g = geocode(self.locations, provider='googlev3')
from geopandas.geocode import geocode
g = geocode(self.locations, provider='googlev3', timeout=2)
self.assertIsInstance(g, gpd.GeoDataFrame)

def test_openmapquest(self):
g = geocode(self.locations, provider='openmapquest')
from geopandas.geocode import geocode
g = geocode(self.locations, provider='openmapquest', timeout=2)
self.assertIsInstance(g, gpd.GeoDataFrame)

@unittest.skip('Nominatim server is unreliable for tests.')
def test_nominatim(self):
g = geocode(self.locations, provider='nominatim')
from geopandas.geocode import geocode
g = geocode(self.locations, provider='nominatim', timeout=2)
self.assertIsInstance(g, gpd.GeoDataFrame)