Skip to content

multigraph remove edge with a key doesn't work (migrated from Trac #326) #323

Closed

Description

@networkx-trac

Original ticket https://networkx.lanl.gov/trac/ticket/326
Reported 2010-03-19 by enginbillur, assigned to @hagberg.

Hello,
When i run the code piece below, i got this error :

G.add_edge(1,2,key='first')
TypeError: add_edge() got an unexpected keyword argument 'key'

G = nx.MultiGraph()[[BR]]
G.add_edge(1,2,key='first')[[BR]]
G.add_edge(1,2,key='second')[[BR]]
G.remove_edge(1,2,key='second')[[BR]]

And when i run the code below:[[BR]]
G = nx.MultiGraph() [[BR]]
G.edges(data=True)[[BR]]
G.add_edge(1,2,data='first')[[BR]]
G.add_edge(1,2,data='second')[[BR]]
G.remove_edge(1,2,data='second')[[BR]]

the program deletes both edges between nodes 1 and 2.. how can i remove just the edge labelled with 'second' key..

Thanks for your help,[[BR]]
Billur Engin

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2010-03-19

    Which version of NetworkX are you using?
    This works with the latest development version.

    '''

    In [18]: G = nx.MultiGraph()

    In [19]: G.add_edge(1,2,key='first')

    In [20]: G.add_edge(1,2,key='second')

    In [21]: G.remove_edge(1,2,key='second')

    In [22]: G.edges(keys=True)
    Out[22]: [(1, 2, 'first')]

    '''

    '''
    In [24]: nx.version
    Out[24]: '1.1.dev1553'
    '''

    In the second question you will need to specify the key explicitly
    when you remove the edge even though you didn't when you added the edge.
    The default is to number the edges with integer keys starting at 0.
    '''
    In [25]: G = nx.MultiGraph()

    In [26]: G.edges(data=True)
    Out[26]: []

    In [27]: G.add_edge(1,2,data='first')

    In [28]: G.add_edge(1,2,data='second')

    In [29]: G.edges(data=True,keys=True)
    Out[29]: [(1, 2, 0, {'data': 'first'}), (1, 2, 1, {'data': 'second'})]

    In [30]: G.remove_edge(1,2,key=1)

    In [31]: G.edges(data=True,keys=True)
    Out[31]: [(1, 2, 0, {'data': 'first'})]

    '''

  2. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2010-03-19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions