-
Notifications
You must be signed in to change notification settings - Fork 830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
consolidate_intersections seems to miss some nodes, and has edges has inconsistent integer types #1241
Comments
As far as I can tell, it's working as expected given how you parameterized it. You set
Yes I think this is the result of recent updates to pandas or numpy... maybe pandas |
There seems to be some inconsistency with how NetworkX handles data with pandas>=2. For example, if we run this snippet with Networkx v3.4 and pandas v1.5.3: import networkx as nx
import pandas as pd
# nodes come saved as a path in a pandas series
nodes = pd.Series([333, 555])
# add the nodes and the edge
G = nx.MultiDiGraph()
G.add_nodes_from(nodes)
G.add_edge(nodes[0], nodes[1])
print(G.nodes) # [333, 555]
print(G.edges) # [(333, 555, 0)] ...the resulting graph nodes are of type int, and the edge is a tuple of ints, as expected. However, if we run that snippet again, but this time with Networkx v3.4.2 and pandas v2.2.3: import networkx as nx
import pandas as pd
# nodes come saved as a path in a pandas series
nodes = pd.Series([333, 555])
# add the nodes and the edge
G = nx.MultiDiGraph()
G.add_nodes_from(nodes)
G.add_edge(nodes[0], nodes[1])
print(G.nodes) # [333, 555]
print(G.edges) # [(333, np.int64(555), 0)] ...the resulting graph nodes are still of type int, and the edge's @LBasara this seems to be what you're seeing with these inconsistent types after consolidating intersections in your graph. It may be worth asking NetworkX in an upstream issue, since this didn't use to happen and this inconsistency probably shouldn't be happening. Edit: for reference, these inconsistent edge |
I opened an upstream issue at networkx/networkx#7763 to see if we get any insights. |
Per the conversation in networkx/networkx#7763, this is an upstream issue with pandas's inconsistency in return types when one is accessing objects with You can use numpy.set_printoptions to prevent this visual inconsistency in the results: import numpy as np
import osmnx as ox
point = 48.1, 0
G = ox.graph.graph_from_point(point, dist=500)
Gp = ox.projection.project_graph(G)
Gc = ox.simplification.consolidate_intersections(Gp, tolerance=10)
print(list(Gc.edges)[:3])
# prints [(0, np.int64(1), 0), (1, np.int64(4), 0), (1, np.int64(0), 0)]
np.set_printoptions(legacy="1.25")
print(list(Gc.edges)[:3])
# prints [(0, 1, 0), (1, 4, 0), (1, 0, 0)] |
Contributing guidelines
Documentation
Existing issues
What operating system and Python version are you using?
Ubuntu 24.10, Python 3.12.7
What OSMnx version are you using?
v2.0.0
Environment packages and versions
How did you install OSMnx?
Other (describe below)
Problem description
Install
Initialized new uv environment, then
uv add jupyterlab 'osmnx>=2' folium geopandas
further added latplotlib and mapclassify for folium visualizatio,
What did you do?
I love the consolidate_intersections function.
I used it on a small bbox (length 6*2km) , used a tolerance of 200m.
I expected to see nodes at each "visual" intersection of edges.
What actually happened instead
There seems to be no nodes where I would expect ones, notably at some dead ends (brown potato), and at road intersections (black potatoes). Red potatoes is at the edge of the bbox so it's ok. The image is zoomed at the west, south-west of the code below.
In addition, there appears to be a mix between the edges formats of the reconstructed Graph (edge source is Python int, edge target is np.int64
:
Complete minimal reproducible example
The text was updated successfully, but these errors were encountered: