None cannot be a node
Package:
networkx
9604
Exception Class:
ValueError
Raise code
"""
On many platforms hashable items also include mutables such as
NetworkX Graphs, though one should be careful that the hash
doesn't change on mutables.
"""
if node_for_adding not in self._succ:
if node_for_adding is None:
raise ValueError("None cannot be a node")
self._succ[node_for_adding] = self.adjlist_inner_dict_factory()
self._pred[node_for_adding] = self.adjlist_inner_dict_factory()
attr_dict = self._node[node_for_adding] = self.node_attr_dict_factory()
attr_dict.update(attr)
else: # update attr even if node already exists
self._node[node_for_adding].update(attr)
Links to the raise (16)
https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/digraph.py#L420 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/digraph.py#L483 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/digraph.py#L622 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/digraph.py#L628 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/digraph.py#L687 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/digraph.py#L693 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/graph.py#L519 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/graph.py#L581 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/graph.py#L881 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/graph.py#L886 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/graph.py#L944 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/graph.py#L949 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/multidigraph.py#L468 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/multidigraph.py#L474 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/multigraph.py#L473 https://github.com/networkx/networkx/blob/906bf82ab7edf0ad4cea067b3be5a4e1cba356a3/networkx/classes/multigraph.py#L478Ways to fix
if node_for_adding not in self._succ:
if node_for_adding is None:
raise ValueError("None cannot be a node")
self._succ[node_for_adding] = self.adjlist_inner_dict_factory()
self._pred[node_for_adding] = self.adjlist_inner_dict_factory()
attr_dict = self._node[node_for_adding] = self.node_attr_dict_factory()
attr_dict.update(attr)
else: # update attr even if node already exists
self._node[node_for_adding].update(attr)
Add a possible fix
Please authorize to post fix