diff globalneighbors/distance.py @ 14:27925261c137

fix broken tests including an aggregious case where we add ourselves as a neighbor to ourself
author Jeff Hammel <k0scist@gmail.com>
date Sun, 25 Jun 2017 14:29:18 -0700
parents 638fad06e556
children 811adc9736eb
line wrap: on
line diff
--- a/globalneighbors/distance.py	Sun Jun 25 14:04:49 2017 -0700
+++ b/globalneighbors/distance.py	Sun Jun 25 14:29:18 2017 -0700
@@ -147,10 +147,13 @@
             new_distance = haversine(*args, r=Rearth)
 
             # insert in order
-            for i in (id1, id2):
-                distances = neighbors.setdefault(i, [])
-
-                insert_distance_bisect(distances, i, new_distance, k)
+            ids = (id1, id2)
+            for i in (0, 1):
+                distances = neighbors.setdefault(ids[i], [])
+                insert_distance_bisect(distances,
+                                       ids[i-1],
+                                       new_distance,
+                                       k)
 
     return neighbors