DaylightingSociety / SocMap

Social Mapping Framework for Twitter
https://socmap.daylightingsociety.org/
BSD 3-Clause "New" or "Revised" License
18 stars 4 forks source link

Networkx wrong attribute name #28

Closed hedonagenda closed 4 years ago

hedonagenda commented 4 years ago

I encountered an error when networkx was updating tweet count of users of a saved network before saving.

Traceback (most recent call last):
  File "./socmap.py", line 113, in <module>
    acquire.getLayers(api, options.layers, options, layer0)
  File "/Users/user/SocMap/acquire.py", line 194, in getLayers
    analyze.saveNetwork(options.mapdir, layer, tweetCounts, nextLayerRTs, nextLayerMentions)
  File "/Users/user/SocMap/analyze.py", line 76, in saveNetwork
    net.node[username]["tweets"] = baseUsers[username]
AttributeError: 'DiGraph' object has no attribute 'node'

i think the attribute is named nodes and not node

milo-trujillo commented 4 years ago

Ah, this is a bug with migrating between networkx versions!

In networkx 1.x, the node method actually appears to be equivalent to nodes, as seen in the following example:

>>> import networkx as nx
>>> net = nx.DiGraph()
>>> net.add_node("foo", layer=0)
>>> net.node["foo"]
{'layer': 0}
>>> net.nodes["foo"]
{'layer': 0}

However, the documentation for networkx only mentions the nodes method now, because node has been removed in networkx 2.0.

That certainly explains why I haven't seen this crash before. Thank you!

milo-trujillo commented 4 years ago

That line appears to be the only instance where we used a now-removed networkx function. Fixed in c8e9f40 (which 100% should have been a proper pull-request, oops), closing issue. Please re-open if you hit a similar method name bug and I missed something.