Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@KostyaEsmukov
Copy link
Member

@KostyaEsmukov KostyaEsmukov commented Apr 1, 2018

This PR adds coordinates validation and issues warnings when they're invalid (or error-prone).

TODO:

Regarding performance degradation – it's ~1.2 times slower with Points and ~1.9 times slower with tuples for me. IMO it's tolerable.

Related discussions: #245 #242 #202

@cffk
Copy link
Contributor

cffk commented Apr 1, 2018

I think that longitudes in the range [-360,360] should be accepted without complaint. In some applications even wider ranges for longitude make sense, e.g., when you're keeping track of how many times you've encircled the globe.

@KostyaEsmukov
Copy link
Member Author

But [-360,360] overlaps the circle two times, which seems ambiguous. How is that different from [-4pi,4pi], which overlaps the circle four times? In that case I think it's better to not restrict longitude range at all, if we tend to think that a longitude outside [-180,180] is not a mistake. Thanks for pointing this out, I'll reason about it.

@KostyaEsmukov
Copy link
Member Author

I moved all the warnings from Distance to Point, which allowed to simplify the validation code significantly. For the reference, the previous commit was 58a37a8.

I also decided to not complain about longitude normalization, because I believe there's nothing error-prone with that (unlike latitude).

I'll leave it open for a day to reason a bit about this all, but I guess it's ready as-is. I would be glad if someone could review (especially the warning messages, as I'm not so confident with English).

@KostyaEsmukov KostyaEsmukov changed the title WIP: Add input validation warnings to the distance routines Add input validation warnings to Point Apr 10, 2018
@KostyaEsmukov
Copy link
Member Author

Ok, I refined one message a little. Now the warnings look like this:

>>> from geopy.distance import distance
>>> distance((170, 20), (170, 10))
[...]/geopy/geopy/point.py:85: UserWarning: Latitude has been normalized, because its absolute value was more than 90. This is probably not what was meant, because the normalized value is on a different pole. If you pass coordinates as positional args, please make sure that the order is (latitude, longitude) or (y, x) in Cartesian terms.  This will cause a ValueError exception in the future versions of geopy.
  UserWarning)
Distance(1096.3515545690054)
>>> distance(20, 170)
[...]/geopy/geopy/point.py:184: UserWarning: A single number has been passed to the Point constructor. This is probably a mistake, because constructing a Point with just a latitude seems senseless. If this is exactly what was meant, then pass the zero longitude explicitly to get rid of this warning.
  UserWarning)
Distance(3318.2210874060056)
>>> distance((20, float("nan")), (10, 170))
[...]/geopy/geopy/point.py:74: UserWarning: Point coordinates should be finite. NaN or inf has been passed as a coordinate.  This will cause a ValueError exception in the future versions of geopy.
  UserWarning)
Distance(nan)

Well, I hope it won't break anything. Merging and prepping the 1.13.0 release.

@KostyaEsmukov KostyaEsmukov merged commit 3135c12 into master Apr 12, 2018
@KostyaEsmukov KostyaEsmukov deleted the distance-warnings branch April 12, 2018 11:38
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.

3 participants