Returns a copy of the graph. The copy method by default returns an independent shallow copy of the graph and attributes. That is, if an attribute is a container, that container is shared by the original an the copy. Use Python's `copy.deepcopy` for new containers.
(self)
| 543 | return False |
| 544 | |
| 545 | def copy(self): |
| 546 | """Returns a copy of the graph. |
| 547 | |
| 548 | The copy method by default returns an independent shallow copy |
| 549 | of the graph and attributes. That is, if an attribute is a |
| 550 | container, that container is shared by the original an the copy. |
| 551 | Use Python's `copy.deepcopy` for new containers. |
| 552 | |
| 553 | Notes |
| 554 | ----- |
| 555 | All copies reproduce the graph structure, but data attributes |
| 556 | may be handled in different ways. There are four types of copies |
| 557 | of a graph that people might want. |
| 558 | |
| 559 | Deepcopy -- A "deepcopy" copies the graph structure as well as |
| 560 | all data attributes and any objects they might contain. |
| 561 | The entire graph object is new so that changes in the copy |
| 562 | do not affect the original object. (see Python's copy.deepcopy) |
| 563 | |
| 564 | Data Reference (Shallow) -- For a shallow copy the graph structure |
| 565 | is copied but the edge, node and graph attribute dicts are |
| 566 | references to those in the original graph. This saves |
| 567 | time and memory but could cause confusion if you change an attribute |
| 568 | in one graph and it changes the attribute in the other. |
| 569 | EasyGraph does not provide this level of shallow copy. |
| 570 | |
| 571 | Independent Shallow -- This copy creates new independent attribute |
| 572 | dicts and then does a shallow copy of the attributes. That is, any |
| 573 | attributes that are containers are shared between the new graph |
| 574 | and the original. This is exactly what `dict.copy()` provides. |
| 575 | You can obtain this style copy using: |
| 576 | |
| 577 | >>> G = eg.path_graph(5) |
| 578 | >>> H = G.copy() |
| 579 | >>> H = eg.Graph(G) |
| 580 | >>> H = G.__class__(G) |
| 581 | |
| 582 | Fresh Data -- For fresh data, the graph structure is copied while |
| 583 | new empty data attribute dicts are created. The resulting graph |
| 584 | is independent of the original and it has no edge, node or graph |
| 585 | attributes. Fresh copies are not enabled. Instead use: |
| 586 | |
| 587 | >>> H = G.__class__() |
| 588 | >>> H.add_nodes_from(G) |
| 589 | >>> H.add_edges_from(G.edges) |
| 590 | |
| 591 | See the Python copy module for more information on shallow |
| 592 | and deep copies, https://docs.python.org/3/library/copy.html. |
| 593 | |
| 594 | Returns |
| 595 | ------- |
| 596 | G : Graph |
| 597 | A copy of the graph. |
| 598 | |
| 599 | See Also |
| 600 | -------- |
| 601 | to_directed: return a directed copy of the graph. |
| 602 |
nothing calls this directly
no test coverage detected