try:
coords = (
(u, v, k, G.nodes[u]["y"], G.nodes[u]["x"], G.nodes[v]["y"], G.nodes[v]["x"])
for u, v, k in G.edges
)
except KeyError: // pragma: no cover
raise KeyError("some edges missing nodes, possibly due to input data clipping issue")
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")
// calculate great circle distances, fill nulls with zeros, then round
dists = great_circle_vec(coords[:, 0], coords[:, 1], coords[:, 2], coords[:, 3])
dists[np.isnan(dists)] = 0
values = zip(uvk, dists.round(precision))
nx.set_edge_attributes(G, values=dict(values), name="length")