This seems to be some odd sort of interaction with properties and maybe subclasses, but I can't get the distance() stuff to work properly. Here's the end of a traceback, with hopefully all the relevant information:
File "F:\code\pyprojects\kproj\controllers.py", line 164, in index theDistance = geography.xdistance(myLoc,theirLoc) File "F:\code\pyprojects\kproj\geography.py", line 46, in xdistance return geopy.distance.distance(x,y).kilometers File "F:\code\Python24\lib\site-packages\geopy-0.93-py2.4.egg\geopy\distance.py" , line 344, in kilometers AttributeError: 'VincentyDistance' object has no attribute '_kilometers'
If I change .kilometers to .miles, I get a similar error:
File "F:\code\pyprojects\kproj\controllers.py", line 164, in index theDistance = geography.xdistance(myLoc,theirLoc) File "F:\code\pyprojects\kproj\geography.py", line 46, in xdistance return geopy.distance.distance(x,y).miles File "F:\code\Python24\lib\site-packages\geopy-0.93-py2.4.egg\geopy\distance.py" , line 92, in miles File "F:\code\Python24\lib\site-packages\geopy-0.93-py2.4.egg\geopy\distance.py" , line 344, in kilometers AttributeError: 'VincentyDistance' object has no attribute '_kilometers'
I think I've seen this before, but I can't remember the code that produced it (it was fixable). Can you post the piece of your geography.py that used geopy.distance.distance? What values are x and y, specifically?
Brian Beck wrote: > I think I've seen this before, but I can't remember the code that > produced it (it was fixable). Can you post the piece of your > geography.py that used geopy.distance.distance? What values are x and > y, specifically?
No need for that, as I think I found the issue. If x and y are exactly equal or are the same object, this happens. My guess is that there's some division by zero or a similar exception thrown before it reaches the self._kilometers = s line, but caught elsewhere so that the end application never sees it.
I can put in a special check in my code for now, but it would be great if this could be fixed, if I've correctly identified the problem that is!
> No need for that, as I think I found the issue. If x and y are exactly > equal or are the same object, this happens. My guess is that there's > some division by zero or a similar exception thrown before it reaches > the self._kilometers = s line, but caught elsewhere so that the end > application never sees it.
Interesting, I thought the algorithm handled this properly, thanks for the heads up.
> No need for that, as I think I found the issue. If x and y are exactly > equal or are the same object, this happens. My guess is that there's > some division by zero or a similar exception thrown before it reaches > the self._kilometers = s line, but caught elsewhere so that the end > application never sees it.
You almost had it. It's a premature return, not an exception. From distance.py, line 284:
if sin_sigma == 0: return 0 # Coincident points
That's the only place in the calculate function where it actually returns a value. It looks like the function was originally written to return the distance, but was later modified to set self._kilometers as its output. The attached patch fixes it. And the results: