Initialize a graph with edges, name, or graph attributes. Parameters ---------- incoming_graph_data : input graph Data to initialize graph. If incoming_graph_data=None (default) an empty graph is created. The data can be an edge list, or any
(self, incoming_graph_data=None, multigraph_input=None, **attr)
| 17 | edge_key_dict_factory = dict |
| 18 | |
| 19 | def __init__(self, incoming_graph_data=None, multigraph_input=None, **attr): |
| 20 | """Initialize a graph with edges, name, or graph attributes. |
| 21 | |
| 22 | Parameters |
| 23 | ---------- |
| 24 | incoming_graph_data : input graph |
| 25 | Data to initialize graph. If incoming_graph_data=None (default) |
| 26 | an empty graph is created. The data can be an edge list, or any |
| 27 | EasyGraph graph object. If the corresponding optional Python |
| 28 | packages are installed the data can also be a NumPy matrix |
| 29 | or 2d ndarray, a SciPy sparse matrix, or a PyGraphviz graph. |
| 30 | |
| 31 | multigraph_input : bool or None (default None) |
| 32 | Note: Only used when `incoming_graph_data` is a dict. |
| 33 | If True, `incoming_graph_data` is assumed to be a |
| 34 | dict-of-dict-of-dict-of-dict structure keyed by |
| 35 | node to neighbor to edge keys to edge data for multi-edges. |
| 36 | A EasyGraphError is raised if this is not the case. |
| 37 | If False, :func:`to_easygraph_graph` is used to try to determine |
| 38 | the dict's graph data structure as either a dict-of-dict-of-dict |
| 39 | keyed by node to neighbor to edge data, or a dict-of-iterable |
| 40 | keyed by node to neighbors. |
| 41 | If None, the treatment for True is tried, but if it fails, |
| 42 | the treatment for False is tried. |
| 43 | |
| 44 | attr : keyword arguments, optional (default= no attributes) |
| 45 | Attributes to add to graph as key=value pairs. |
| 46 | |
| 47 | See Also |
| 48 | -------- |
| 49 | convert |
| 50 | |
| 51 | Examples |
| 52 | -------- |
| 53 | >>> G = eg.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc |
| 54 | >>> G = eg.Graph(name="my graph") |
| 55 | >>> e = [(1, 2), (2, 3), (3, 4)] # list of edges |
| 56 | >>> G = eg.Graph(e) |
| 57 | |
| 58 | Arbitrary graph attribute pairs (key=value) may be assigned |
| 59 | |
| 60 | >>> G = eg.Graph(e, day="Friday") |
| 61 | >>> G.graph |
| 62 | {'day': 'Friday'} |
| 63 | |
| 64 | """ |
| 65 | self.edge_key_dict_factory = self.edge_key_dict_factory |
| 66 | # multigraph_input can be None/True/False. So check "is not False" |
| 67 | if isinstance(incoming_graph_data, dict) and multigraph_input is not False: |
| 68 | DiGraph.__init__(self) |
| 69 | try: |
| 70 | convert.from_dict_of_dicts( |
| 71 | incoming_graph_data, create_using=self, multigraph_input=True |
| 72 | ) |
| 73 | self.graph.update(attr) |
| 74 | except Exception as err: |
| 75 | if multigraph_input is True: |
| 76 | raise EasyGraphError( |
nothing calls this directly
no test coverage detected