-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot add attributes to existing edges #241
Comments
I believe you can do this with I agree this is far from optimal though and I kinda hate that right now we have to use |
Would |
Yes @nwlandry I think that is very close to what I want, only difference is I was looking for something that operated on a single edge at a time rather than a dictionary of edges, but that is fine. Perhaps this should be added to "See Also" for |
These are great suggestions. Let's keep this issue open until I implement your suggestions. |
I added |
I want to add attributes to edges after I have created a hypergraph with
H = xgi.Hypergraph(incoming_data=hyperedge_list)
and I do not think it is possible right now (please correct if I am wrong).Note that this issue is only relevant when the hypergraph is constructed first, then edge attributes added later. I could instead create an empty hypergraph and add edges one at a time with the relevant attributes (this is what I will do for now). In fact this would save me looping over the edges a second time after construction. However, in my particular use case I would prefer the semantics I describe because I think (1) they are more clear/general and (ii) would allow me to add attributes without constructing a new hypergraph. But the functionality is not sctrictly necessary.
It is possible to add or update attributes of existing nodes with
H.add_node(existing_node, **attr)
, since per the docsHowever, the same does not work for edges, because
H.add_edge(existing_edge_members, **attr)
creates a multi-edge, andH.add_edge(edge_id, **attr)
fails becauseH.add_edge
expects an iterable representing a hyperedge as its first argument, not an edge ID.The simplest fix I can think of is to allow
H.add_edge
to accept an edge ID, check if the edge exists and if so modify provided attributes, or raise an error if the edge ID is not present. However, I think that overloadsadd_edge
in a confusing way (already the case withadd_node
), so it may be better to define new functions for attribute addition/updates, i.e.,H.update_node_attributes(node, **attr)
andH.update_edge_attributes(edge_id, **attr)
,with the edge function accepting an edge ID rather than the hyperedge itself. These functions might return an error if the node/edge does not exist and/or a warning if the attribute does not already exist for the node/edge, both of which could be managed with boolean arguments to the functions. This setup pushes the multi-edge issue onto the user, since whether multi-edges should have the same attributes is generally ambiguous.
I think this is related to discussions in #126 and #175.
The text was updated successfully, but these errors were encountered: