Closed Joshuaalbert closed 3 years ago
Thank you for the message and the nice catch!
I understand that this is a problem because it is not even possible to store the specification of the edge features in a networkx graph that does not have edges.
Our intent was to make sure that the user always has a way to specify shapes and types of edges and nodes, even for graphs that do no have any edges or any nodes, so there is no room for misunderstandings. This is one of the reasons why we prefer working with data_dicts, or building GraphsTuples directly, and the networkx methods are only intended as helper methods, but we expect that in some of the most sophisticated use cases, users may have to do the conversion from networkx to data dict manually.
Specifically, networkxs_to_graphs_tuple
is just a light wrapper that first converts to a list of data_dicts (which have no problem in specifying empty arrays with trailing shapes for graphs with 0 nodes or 0 edges), and then transform those into a graphs tuple using data_dicts_to_graphs_tuple
. We provided the node_shape_hint
and edge_shape_hint
attributes in networkxs_to_graphs_tuple
, so the networkx graph can be converted into a data_dict with fully specified shapes even for graphs in the batch that have 0 edges/nodes, as well as a the data_type_hint
for the type.
I think passing this argument edge_shape_hint
(while a bit annoying) should make it work for your use case. Could you confirm?
It should be possible to implement the behavior that you are suggesting, but we slightly lean on preferring the user to specify it explicitly, in the cases where the data structure does not support it.
(closing due to inactivity)
When you do
networkxs_to_graphs_tuple(graphs)
wheregraphs
is a list of networkx graphs and some don't have edges, then it will raise an error:But there are cases when these graphs which lack edges should be transparently treated as a graph with empty edge attribute. E.g. if you're using
nx
functionality to remove nodes and this results in a completely disconnected graph. This should not result innetworkxs_to_graphs_tuple
failing.