MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / remove_edge

Method remove_edge

easygraph/classes/directed_multigraph.py:180–234  ·  view source on GitHub ↗

Remove an edge between u and v. Parameters ---------- u, v : nodes Remove an edge between nodes u and v. key : hashable identifier, optional (default=None) Used to distinguish multiple edges between a pair of nodes. If None remove

(self, u, v, key=None)

Source from the content-addressed store, hash-verified

178 return key
179
180 def remove_edge(self, u, v, key=None):
181 """Remove an edge between u and v.
182
183 Parameters
184 ----------
185 u, v : nodes
186 Remove an edge between nodes u and v.
187 key : hashable identifier, optional (default=None)
188 Used to distinguish multiple edges between a pair of nodes.
189 If None remove a single (arbitrary) edge between u and v.
190
191 Raises
192 ------
193 EasyGraphError
194 If there is not an edge between u and v, or
195 if there is no edge with the specified key.
196
197 See Also
198 --------
199 remove_edges_from : remove a collection of edges
200
201 Examples
202 --------
203 >>> G = eg.MultiDiGraph()
204 >>> G.add_edges_from([(1, 2), (1, 2), (1, 2)]) # key_list returned
205 [0, 1, 2]
206 >>> G.remove_edge(1, 2) # remove a single (arbitrary) edge
207
208 For edges with keys
209
210 >>> G = eg.MultiDiGraph()
211 >>> G.add_edge(1, 2, key="first")
212 'first'
213 >>> G.add_edge(1, 2, key="second")
214 'second'
215 >>> G.remove_edge(1, 2, key="second")
216
217 """
218 try:
219 d = self._adj[u][v]
220 except KeyError as err:
221 raise EasyGraphError(f"The edge {u}-{v} is not in the graph.") from err
222 # remove the edge with specified data
223 if key is None:
224 d.popitem()
225 else:
226 try:
227 del d[key]
228 except KeyError as err:
229 msg = f"The edge {u}-{v} with key {key} is not in the graph."
230 raise EasyGraphError(msg) from err
231 if len(d) == 0:
232 # remove the key entries if last edge
233 del self._adj[u][v]
234 del self._pred[v][u]
235
236 @property
237 def edges(self):

Callers

nothing calls this directly

Calls 1

EasyGraphErrorClass · 0.90

Tested by

no test coverage detected