{"action":"created","issue":{"url":"https://api.github.com/repos/networkx/networkx/issues/1539","labels_url":"https://api.github.com/repos/networkx/networkx/issues/1539/labels{/name}","comments_url":"https://api.github.com/repos/networkx/networkx/issues/1539/comments","events_url":"https://api.github.com/repos/networkx/networkx/issues/1539/events","html_url":"https://github.com/networkx/networkx/issues/1539","id":79255974,"number":1539,"title":"Possible bug in nx.relabel_nodes","user":{"login":"AgostinoSturaro","id":1441393,"avatar_url":"https://avatars.githubusercontent.com/u/1441393?v=3","gravatar_id":"","url":"https://api.github.com/users/AgostinoSturaro","html_url":"https://github.com/AgostinoSturaro","followers_url":"https://api.github.com/users/AgostinoSturaro/followers","following_url":"https://api.github.com/users/AgostinoSturaro/following{/other_user}","gists_url":"https://api.github.com/users/AgostinoSturaro/gists{/gist_id}","starred_url":"https://api.github.com/users/AgostinoSturaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgostinoSturaro/subscriptions","organizations_url":"https://api.github.com/users/AgostinoSturaro/orgs","repos_url":"https://api.github.com/users/AgostinoSturaro/repos","events_url":"https://api.github.com/users/AgostinoSturaro/events{/privacy}","received_events_url":"https://api.github.com/users/AgostinoSturaro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-05-22T03:00:09Z","updated_at":"2015-05-22T03:34:54Z","closed_at":null,"body":"Relabeling nodes to their own id when `copy=False` can create problems\r\n\r\n    import networkx as nx\r\n    \r\n    G = nx.Graph()\r\n    G.add_nodes_from([(0, {'data': 0}), (1, {'data': 0}), (2, {'data': 0}), (3, {'data': 0}), (4, {'data': 0})])\r\n    print('G.nodes(data=True) = ' + str(G.nodes(data=True)))\r\n    \r\n    # this will print an empty graph, or a graph where nodes lost their data\r\n    nx.relabel_nodes(G, mapping={0: 0, 1: 1, 2: 2, 3: 3, 4: 4}, copy=False)\r\n    print('G.nodes(data=True) = ' + str(G.nodes(data=True)))\r\n    \r\n    # this works\r\n    nx.relabel_nodes(G, mapping={0: 1, 1: 2, 2: 3, 3: 4, 4: 5}, copy=False)\r\n    print('G.nodes(data=True) = ' + str(G.nodes(data=True)))\r\n\r\nNow, why would I want to relabel nodes the same as before?\r\nThis was actually a corner case of an algorithm that did relabeling. It was supposed to do nothing in this case, but instead it messed the graph, so I got to notice."},"comment":{"url":"https://api.github.com/repos/networkx/networkx/issues/comments/104492869","html_url":"https://github.com/networkx/networkx/issues/1539#issuecomment-104492869","issue_url":"https://api.github.com/repos/networkx/networkx/issues/1539","id":104492869,"user":{"login":"AgostinoSturaro","id":1441393,"avatar_url":"https://avatars.githubusercontent.com/u/1441393?v=3","gravatar_id":"","url":"https://api.github.com/users/AgostinoSturaro","html_url":"https://github.com/AgostinoSturaro","followers_url":"https://api.github.com/users/AgostinoSturaro/followers","following_url":"https://api.github.com/users/AgostinoSturaro/following{/other_user}","gists_url":"https://api.github.com/users/AgostinoSturaro/gists{/gist_id}","starred_url":"https://api.github.com/users/AgostinoSturaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgostinoSturaro/subscriptions","organizations_url":"https://api.github.com/users/AgostinoSturaro/orgs","repos_url":"https://api.github.com/users/AgostinoSturaro/repos","events_url":"https://api.github.com/users/AgostinoSturaro/events{/privacy}","received_events_url":"https://api.github.com/users/AgostinoSturaro/received_events","type":"User","site_admin":false},"created_at":"2015-05-22T03:34:54Z","updated_at":"2015-05-22T03:34:54Z","body":"That's what I do in my code right now. Having this fix in the library would avoid nasty surprises like the one I had.\r\n\r\nHowever, I can't quite understand why the function would behave like that, maybe it's worth having a look at it."}}