// turn the coordinates into a DataFrame indexed by u, v, k
cols = ["u", "v", "k", "u_y", "u_x", "v_y", "v_x"]
df = pd.DataFrame(coords, columns=cols).set_index(["u", "v", "k"])
// calculate great circle distances, fill nulls with zeros, then round
dists = distance.great_circle_vec(df["u_y"], df["u_x"], df["v_y"], df["v_x"])
dists = dists.fillna(value=0).round(precision)
After Change
// extract edge IDs and corresponding coordinates from their nodes
uvk = tuple(G.edges)
x = G.nodes(data="x")
y = G.nodes(data="y")
try:
coords = np.array([(y[u], x[u], y[v], x[v]) for u, v, k in uvk])
except KeyError: // pragma: no cover
raise KeyError("some edges missing nodes, possibly due to input data clipping issue")