This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.


PyDiGraph.remove_node_retain_edges(node, /, use_outgoing=False, condition=None)#

Remove a node from the graph and add edges from all predecessors to all successors

By default the data/weight on edges into the removed node will be used for the retained edges.

This function has a minimum time complexity of \(\mathcal O(e_i e_o)\), where \(e_i\) and \(e_o\) are the numbers of incoming and outgoing edges respectively. If your condition can be cast as an equality between two hashable quantities, consider using remove_node_retain_edges_by_key() instead, or if your condition is referential object identity of the edge weights, consider remove_node_retain_edges_by_id().

  • node (int) – The index of the node to remove. If the index is not present in the graph it will be ingored and this function willl have no effect.

  • use_outgoing (bool) – If set to true the weight/data from the edge outgoing from node will be used in the retained edge instead of the default weight/data from the incoming edge.

  • condition

    A callable that will be passed 2 edge weight/data objects, one from the incoming edge to node the other for the outgoing edge, and will return a bool on whether an edge should be retained. For example setting this kwarg to:

    lambda in_edge, out_edge: in_edge == out_edge

    would only retain edges if the input edge to node had the same data payload as the outgoing edge.