Returns the attribute dictionary of node n. This is identical to `G[n]`. Parameters ---------- n : nodes Returns ------- node_dict : dictionary The node attribute dictionary. Examples -------- >>> G = nx.path_graph(4) # or DiGraph etc >>> G[0]
(graph, n)
| 445 | |
| 446 | |
| 447 | def get_node_data(graph, n): |
| 448 | """Returns the attribute dictionary of node n. |
| 449 | |
| 450 | This is identical to `G[n]`. |
| 451 | |
| 452 | Parameters |
| 453 | ---------- |
| 454 | n : nodes |
| 455 | |
| 456 | Returns |
| 457 | ------- |
| 458 | node_dict : dictionary |
| 459 | The node attribute dictionary. |
| 460 | |
| 461 | Examples |
| 462 | -------- |
| 463 | >>> G = nx.path_graph(4) # or DiGraph etc |
| 464 | >>> G[0] |
| 465 | {} |
| 466 | |
| 467 | Warning: Assigning to `G[n]` is not permitted. |
| 468 | But it is safe to assign attributes `G[n]['foo']` |
| 469 | |
| 470 | >>> G[0]['weight'] = 7 |
| 471 | >>> G[0]['weight'] |
| 472 | 7 |
| 473 | |
| 474 | >>> G = nx.path_graph(4) # or DiGraph etc |
| 475 | >>> G.get_node_data(0, 1) |
| 476 | {} |
| 477 | |
| 478 | """ |
| 479 | if graph.graph_type == graph_def_pb2.ARROW_PROPERTY: |
| 480 | n = graph._convert_to_label_id_tuple(n) |
| 481 | op = dag_utils.report_graph( |
| 482 | graph, |
| 483 | types_pb2.NODE_DATA, |
| 484 | node=json.dumps(n).encode("utf-8", errors="ignore"), |
| 485 | ) |
| 486 | archive = op.eval() |
| 487 | return msgpack.loads(archive.get_bytes(), use_list=False) |
no test coverage detected