You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frompyvis.networkimportNetworkfromitertoolsimportcombinationsnodes= [str(n) forninrange(10)]
edges=list(combinations(nodes, 2))
nt=Network()
# casts all node IDs from str to int silently for no reason other than it cannt.add_nodes(nodes)
# node IDs not cast to int, raises AssertionError indicating that nodes are missing# even though the node IDs are the same datatype in the sourcent.add_edges(edges)
Just my $0.02, pyvis should not be type-casting node IDs at all and especially not silently and inconsistently. I spent hours beating my head into the keyboard trying to figure out what was wrong with my code and why I was getting an exception for a missing node when adding edges to my network. I thought that I was somehow filtering my dataset in such a way that I was losing a node that would be in an edge. Additionally, AssertionError is inappropriate to use here because it is disabled if the Python interpreter is running in any optimization mode. Raising TypeError would be more appropriate as it will not be disabled if the Python interpreter is running in an optimization mode.
The text was updated successfully, but these errors were encountered:
norweeg
changed the title
Numeric string node ID silently cast to in in add_nodes but not add_edges, rasies
Numeric string node ID silently cast from str to int in in add_nodes but not add_edges, rasies AssertionErrorApr 3, 2024
norweeg
added a commit
to norweeg/pyvis
that referenced
this issue
Apr 3, 2024
* removes unnecessary and silent type conversion of numeric node IDs
* add_edges using node IDs' original type no longer raises exception
* refactored coincidental inappropriate usage of assert for type-checking/control logic in add_node and add_nodes to raise appropriate exceptions instead
norweeg
changed the title
Numeric string node ID silently cast from str to int in in add_nodes but not add_edges, rasies AssertionError
Numeric string node ID silently cast from str to int in in add_nodes but not add_edges, raises AssertionErrorApr 3, 2024
Just my $0.02, pyvis should not be type-casting node IDs at all and especially not silently and inconsistently. I spent hours beating my head into the keyboard trying to figure out what was wrong with my code and why I was getting an exception for a missing node when adding edges to my network. I thought that I was somehow filtering my dataset in such a way that I was losing a node that would be in an edge. Additionally,
AssertionError
is inappropriate to use here because it is disabled if the Python interpreter is running in any optimization mode. RaisingTypeError
would be more appropriate as it will not be disabled if the Python interpreter is running in an optimization mode.The text was updated successfully, but these errors were encountered: