Closed virgilxw closed 3 months ago
Thanks for the report. Though we don't use connected_component_subgraphs
in our code. Can you post the full traceback?
AttributeError Traceback (most recent call last) Cell In[12], line 8 4 nx.set_node_attributes(primal, degree, 'degree') 6 graph = momepy.node_degree(primal, name='degree') ----> 8 nodes, edges, sw = momepy.nx_to_gdf(graph, points=True, lines=True, 9 spatial_weights=True) 11 f, ax = plt.subplots(figsize=(10, 10)) 12 nodes.plot(ax=ax, column='degree', cmap='tab20b', markersize=(nodes['degree'] * 100), zorder=2)
File ~/miniforge3/envs/processor/lib/python3.12/site-packages/momepy/utils.py:438, in nx_to_gdf(net, points, lines, spatial_weights, nodeID) 435 for nid, n in enumerate(net): 436 net.nodes[n][nodeID] = nid --> 438 return _primal_to_gdf( 439 net, 440 points=points, 441 lines=lines, 442 spatial_weights=spatial_weights, 443 node_id=nodeID, 444 )
File ~/miniforge3/envs/processor/lib/python3.12/site-packages/momepy/utils.py:319, in _primal_to_gdf(net, points, lines, spatial_weights, node_id) 316 gdf_nodes = _points_to_gdf(net) 318 if spatial_weights is True: --> 319 weights = libpysal.weights.W.from_networkx(net) ... --> 352 sparse_matrix = nx.to_scipy_sparse_matrix(graph) 353 w = WSP(sparse_matrix).to_W() 354 return w
AttributeError: module 'networkx' has no attribute 'to_scipy_sparse_matrix' Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
It is truncated. Can you open the full version in VS Code and copy that please? Also, this shows a different error than reported above?
I think that the issue comes from the outdated libpysal
in your environment. The version 4.5.1 is more than 2 years old. I suggest updating libpysal (and ideally also momepy) to their latest versions.
Closing due to missing info. Can reopen if it pops up again in relevant versions.
Describe the problem
AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs' occurs when networkx is used because the function is depreciated in networkx 2.3
https://stackoverflow.com/questions/61154740/attributeerror-module-networkx-has-no-attribute-connected-component-subgraph
Steps to reproduce
Momepy implementation
degree = dict(nx.degree(primal)) nx.set_node_attributes(primal, degree, 'degree')
graph = momepy.node_degree(primal, name='degree')
nodes, edges, sw = momepy.nx_to_gdf(graph, points=True, lines=True, spatial_weights=True)
f, ax = plt.subplots(figsize=(10, 10)) nodes.plot(ax=ax, column='degree', cmap='tab20b', markersize=(nodes['degree'] * 100), zorder=2) edges.plot(ax=ax, color='lightgrey', zorder=1) ax.set_axis_off() plt.show()
Versions of your packages
Your operating system
No response
Additional context
No response