Skip to content

Commit 16d91e8

Browse files
authored
Docstring examples for algorithms/operators/all.py (networkx#6974)
Add docstring examples for union and intersection operators
1 parent 149c103 commit 16d91e8

File tree

1 file changed

+40
-0
lines changed
  • networkx/algorithms/operators

1 file changed

+40
-0
lines changed

networkx/algorithms/operators/all.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ def union_all(graphs, rename=()):
5050
If a graph attribute is present in multiple graphs, then the value
5151
from the last graph in the list with that attribute is used.
5252
53+
Examples
54+
--------
55+
>>> G1 = nx.Graph([(1, 2), (2, 3)])
56+
>>> G2 = nx.Graph([(4, 5), (5, 6)])
57+
>>> result_graph = nx.union_all([G1, G2])
58+
>>> result_graph.nodes()
59+
NodeView((1, 2, 3, 4, 5, 6))
60+
>>> result_graph.edges()
61+
EdgeView([(1, 2), (2, 3), (4, 5), (5, 6)])
62+
5363
See Also
5464
--------
5565
union
@@ -125,6 +135,16 @@ def disjoint_union_all(graphs):
125135
NetworkXError
126136
In case of mixed type graphs, like MultiGraph and Graph, or directed and undirected graphs.
127137
138+
Example
139+
-------
140+
>>> G1 = nx.Graph([(1, 2), (2, 3)])
141+
>>> G2 = nx.Graph([(4, 5), (5, 6)])
142+
>>> U = nx.disjoint_union_all([G1, G2])
143+
>>> list(U.nodes())
144+
[0, 1, 2, 3, 4, 5]
145+
>>> list(U.edges())
146+
[(0, 1), (1, 2), (3, 4), (4, 5)]
147+
128148
Notes
129149
-----
130150
For operating on mixed type graphs, they should be converted to the same type.
@@ -169,6 +189,16 @@ def compose_all(graphs):
169189
NetworkXError
170190
In case of mixed type graphs, like MultiGraph and Graph, or directed and undirected graphs.
171191
192+
Example
193+
-------
194+
>>> G1 = nx.Graph([(1, 2), (2, 3)])
195+
>>> G2 = nx.Graph([(3, 4), (5, 6)])
196+
>>> C = nx.compose_all([G1, G2])
197+
>>> list(C.nodes())
198+
[1, 2, 3, 4, 5, 6]
199+
>>> list(C.edges())
200+
[(1, 2), (2, 3), (3, 4), (5, 6)]
201+
172202
Notes
173203
-----
174204
For operating on mixed type graphs, they should be converted to the same type.
@@ -246,6 +276,16 @@ def intersection_all(graphs):
246276
>>> gh.nodes(data=True)
247277
NodeDataView({0: {'new_capacity': 2}, 1: {'new_capacity': 3}})
248278
279+
Example
280+
-------
281+
>>> G1 = nx.Graph([(1, 2), (2, 3)])
282+
>>> G2 = nx.Graph([(2, 3), (3, 4)])
283+
>>> R = nx.intersection_all([G1, G2])
284+
>>> list(R.nodes())
285+
[2, 3]
286+
>>> list(R.edges())
287+
[(2, 3)]
288+
249289
"""
250290
R = None
251291

0 commit comments

Comments
 (0)