Skip to content

Commit

Permalink
Vincenty: add deprecation warning (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaEsmukov committed May 11, 2018
1 parent 5a8cb77 commit 3ef9abd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions geopy/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,15 @@ class vincenty(Distance):

ellipsoid_key = None
ELLIPSOID = None
_show_deprecation_warning = True

def __init__(self, *args, **kwargs):
if self._show_deprecation_warning:
warnings.warn('Vincenty is deprecated and is going to be removed '
'in geopy 2.0. Use `geopy.distance.geodesic` '
'(or the default `geopy.distance.distance`) '
'instead, which is more accurate and always converges.',
DeprecationWarning)
self.set_ellipsoid(kwargs.pop('ellipsoid', 'WGS-84'))
self.iterations = kwargs.pop('iterations', 20)
major, minor, f = self.ELLIPSOID # pylint: disable=W0612
Expand Down
7 changes: 7 additions & 0 deletions test/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import math
import unittest
import warnings
from mock import patch

from geopy import distance as geopy_distance
from geopy.point import Point
Expand Down Expand Up @@ -291,6 +292,11 @@ def test_lonlat_function(self):
point = lonlat(*newport_ri_xy)
self.assertEqual(point, (41.49008, -71.312796, 0))

def test_vincenty_deprecation_warning(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
VincentyDistance((0, 0), (10, 10))
self.assertEqual(1, len(w))

class TestWhenComputingGreatCircleDistance(CommonDistanceCases,
unittest.TestCase):
Expand All @@ -307,6 +313,7 @@ def test_should_compute_destination_for_half_trip_around_equator(self):
self.assertAlmostEqual(destination.longitude, 180)


@patch.object(VincentyDistance, '_show_deprecation_warning', False)
class TestWhenComputingVincentyDistance(CommonDistanceCases,
unittest.TestCase):

Expand Down

0 comments on commit 3ef9abd

Please sign in to comment.