Original ticket https://networkx.lanl.gov/trac/ticket/583
Reported 2011-06-25 by @dschult, assigned to @dschult.
The get_edge_data method should be enhanced with keyword control of what gets returned.
The motivation for this change is to make it simpler to write algorithms that access edge data, especially when handling multigraphs. See #574 for a detailed discussion and examples.
The proposed signature is:
'''
G.get_edge_data(u,v,key=None,data_key=None,default=1,missing=None,combine=list)
'''
Briefly, when '''data_key is None''', this is like '''G.adj[u][v]'''.
But when '''data_key''' is specified, this is like '''G.adj[u][v].get(data_key, default) '''
If the edge doesn't exist, '''missing''' is returned.
The '''key''' and '''combine''' arguments are used only for multigraphs. If key is specified, use the same behavior on the data dict '''G.adj[u][v][key]'''. If '''key is None''' and '''data_key''' is specified, the list of values obtained is sent to the function combine, which defaults to '''list''', but common examples would be '''min''' or '''sum'''.
This is not backward compatible since the current method uses the '''default''' keyword to supply a value when the edge does not exist instead of when the edge data key does not exist as proposed here.
Suggestions on other desired features? names for arguments? anything else?
Original ticket https://networkx.lanl.gov/trac/ticket/583
Reported 2011-06-25 by @dschult, assigned to @dschult.
The get_edge_data method should be enhanced with keyword control of what gets returned.
The motivation for this change is to make it simpler to write algorithms that access edge data, especially when handling multigraphs. See #574 for a detailed discussion and examples.
The proposed signature is:
'''
G.get_edge_data(u,v,key=None,data_key=None,default=1,missing=None,combine=list)
'''
Briefly, when '''data_key is None''', this is like '''G.adj[u][v]'''.
But when '''data_key''' is specified, this is like '''G.adj[u][v].get(data_key, default) '''
If the edge doesn't exist, '''missing''' is returned.
The '''key''' and '''combine''' arguments are used only for multigraphs. If key is specified, use the same behavior on the data dict '''G.adj[u][v][key]'''. If '''key is None''' and '''data_key''' is specified, the list of values obtained is sent to the function combine, which defaults to '''list''', but common examples would be '''min''' or '''sum'''.
This is not backward compatible since the current method uses the '''default''' keyword to supply a value when the edge does not exist instead of when the edge data key does not exist as proposed here.
Suggestions on other desired features? names for arguments? anything else?