summaryrefslogtreecommitdiff
path: root/networkx/readwrite
diff options
context:
space:
mode:
authorJarrod Millman <jarrod.millman@gmail.com>2020-08-19 13:56:18 -0700
committerGitHub <noreply@github.com>2020-08-19 13:56:18 -0700
commit99fc1bb6690ac1a45124db2a01c12fd64dcb109b (patch)
tree1891fc18beca7b6d1005b9ce32175ddfed29870f /networkx/readwrite
parent7b3ad34e1be1c61dbccae3df920afb898e2eb8ad (diff)
downloadnetworkx-99fc1bb6690ac1a45124db2a01c12fd64dcb109b.tar.gz
Format python in docstrings (#4168)
* Format code w/ black * Format docstrings w/ black * Manual cleanup * Tell pytest to ignore planned deprecations * Don't call plt.show during testing * Another known deprecation * DOC: rm duplicate line from docstring example * Minor cleanup Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Diffstat (limited to 'networkx/readwrite')
-rw-r--r--networkx/readwrite/adjlist.py14
-rw-r--r--networkx/readwrite/edgelist.py58
-rw-r--r--networkx/readwrite/gexf.py10
-rw-r--r--networkx/readwrite/gml.py4
-rw-r--r--networkx/readwrite/graph6.py6
-rw-r--r--networkx/readwrite/graphml.py26
-rw-r--r--networkx/readwrite/json_graph/adjacency.py4
-rw-r--r--networkx/readwrite/json_graph/jit.py4
-rw-r--r--networkx/readwrite/json_graph/node_link.py12
-rw-r--r--networkx/readwrite/json_graph/tree.py8
-rw-r--r--networkx/readwrite/multiline_adjlist.py42
-rw-r--r--networkx/readwrite/nx_shp.py2
-rw-r--r--networkx/readwrite/nx_yaml.py10
-rw-r--r--networkx/readwrite/sparse6.py6
-rw-r--r--networkx/readwrite/tests/test_gml.py4
-rw-r--r--networkx/readwrite/tests/test_graphml.py4
16 files changed, 103 insertions, 111 deletions
diff --git a/networkx/readwrite/adjlist.py b/networkx/readwrite/adjlist.py
index 0c9b1083..2de048f7 100644
--- a/networkx/readwrite/adjlist.py
+++ b/networkx/readwrite/adjlist.py
@@ -103,12 +103,12 @@ def write_adjlist(G, path, comments="#", delimiter=" ", encoding="utf-8"):
Examples
--------
>>> G = nx.path_graph(4)
- >>> nx.write_adjlist(G,"test.adjlist")
+ >>> nx.write_adjlist(G, "test.adjlist")
The path can be a filehandle or a string with the name of the file. If a
filehandle is provided, it has to be opened in 'wb' mode.
- >>> fh = open("test.adjlist",'wb')
+ >>> fh = open("test.adjlist", "wb")
>>> nx.write_adjlist(G, fh)
Notes
@@ -166,11 +166,7 @@ def parse_adjlist(
Examples
--------
- >>> lines = ['1 2 5',
- ... '2 3 4',
- ... '3 5',
- ... '4',
- ... '5']
+ >>> lines = ["1 2 5", "2 3 4", "3 5", "4", "5"]
>>> G = nx.parse_adjlist(lines, nodetype=int)
>>> nodes = [1, 2, 3, 4, 5]
>>> all(node in G for node in nodes)
@@ -257,12 +253,12 @@ def read_adjlist(
The path can be a filehandle or a string with the name of the file. If a
filehandle is provided, it has to be opened in 'rb' mode.
- >>> fh = open("test.adjlist", 'rb')
+ >>> fh = open("test.adjlist", "rb")
>>> G = nx.read_adjlist(fh)
Filenames ending in .gz or .bz2 will be compressed.
- >>> nx.write_adjlist(G,"test.adjlist.gz")
+ >>> nx.write_adjlist(G, "test.adjlist.gz")
>>> G = nx.read_adjlist("test.adjlist.gz")
The optional nodetype is a function to convert node strings to nodetype.
diff --git a/networkx/readwrite/edgelist.py b/networkx/readwrite/edgelist.py
index a9d24c96..239efdbe 100644
--- a/networkx/readwrite/edgelist.py
+++ b/networkx/readwrite/edgelist.py
@@ -63,8 +63,8 @@ def generate_edgelist(G, delimiter=" ", data=True):
Examples
--------
>>> G = nx.lollipop_graph(4, 3)
- >>> G[1][2]['weight'] = 3
- >>> G[3][4]['capacity'] = 12
+ >>> G[1][2]["weight"] = 3
+ >>> G[3][4]["capacity"] = 12
>>> for line in nx.generate_edgelist(G, data=False):
... print(line)
0 1
@@ -89,7 +89,7 @@ def generate_edgelist(G, delimiter=" ", data=True):
4 5 {}
5 6 {}
- >>> for line in nx.generate_edgelist(G,data=['weight']):
+ >>> for line in nx.generate_edgelist(G, data=["weight"]):
... print(line)
0 1
0 2
@@ -148,19 +148,19 @@ def write_edgelist(G, path, comments="#", delimiter=" ", data=True, encoding="ut
Examples
--------
- >>> G=nx.path_graph(4)
+ >>> G = nx.path_graph(4)
>>> nx.write_edgelist(G, "test.edgelist")
- >>> G=nx.path_graph(4)
- >>> fh=open("test.edgelist",'wb')
+ >>> G = nx.path_graph(4)
+ >>> fh = open("test.edgelist", "wb")
>>> nx.write_edgelist(G, fh)
>>> nx.write_edgelist(G, "test.edgelist.gz")
>>> nx.write_edgelist(G, "test.edgelist.gz", data=False)
- >>> G=nx.Graph()
- >>> G.add_edge(1,2,weight=7,color='red')
- >>> nx.write_edgelist(G,'test.edgelist',data=False)
- >>> nx.write_edgelist(G,'test.edgelist',data=['color'])
- >>> nx.write_edgelist(G,'test.edgelist',data=['color','weight'])
+ >>> G = nx.Graph()
+ >>> G.add_edge(1, 2, weight=7, color="red")
+ >>> nx.write_edgelist(G, "test.edgelist", data=False)
+ >>> nx.write_edgelist(G, "test.edgelist", data=["color"])
+ >>> nx.write_edgelist(G, "test.edgelist", data=["color", "weight"])
See Also
--------
@@ -205,9 +205,7 @@ def parse_edgelist(
--------
Edgelist with no data:
- >>> lines = ["1 2",
- ... "2 3",
- ... "3 4"]
+ >>> lines = ["1 2", "2 3", "3 4"]
>>> G = nx.parse_edgelist(lines, nodetype=int)
>>> list(G)
[1, 2, 3, 4]
@@ -216,9 +214,7 @@ def parse_edgelist(
Edgelist with data in Python dictionary representation:
- >>> lines = ["1 2 {'weight': 3}",
- ... "2 3 {'weight': 27}",
- ... "3 4 {'weight': 3.0}"]
+ >>> lines = ["1 2 {'weight': 3}", "2 3 {'weight': 27}", "3 4 {'weight': 3.0}"]
>>> G = nx.parse_edgelist(lines, nodetype=int)
>>> list(G)
[1, 2, 3, 4]
@@ -227,10 +223,8 @@ def parse_edgelist(
Edgelist with data in a list:
- >>> lines = ["1 2 3",
- ... "2 3 27",
- ... "3 4 3.0"]
- >>> G = nx.parse_edgelist(lines, nodetype=int, data=(('weight',float),))
+ >>> lines = ["1 2 3", "2 3 27", "3 4 3.0"]
+ >>> G = nx.parse_edgelist(lines, nodetype=int, data=(("weight", float),))
>>> list(G)
[1, 2, 3, 4]
>>> list(G.edges(data=True))
@@ -342,22 +336,22 @@ def read_edgelist(
Examples
--------
>>> nx.write_edgelist(nx.path_graph(4), "test.edgelist")
- >>> G=nx.read_edgelist("test.edgelist")
+ >>> G = nx.read_edgelist("test.edgelist")
- >>> fh=open("test.edgelist", 'rb')
- >>> G=nx.read_edgelist(fh)
+ >>> fh = open("test.edgelist", "rb")
+ >>> G = nx.read_edgelist(fh)
>>> fh.close()
- >>> G=nx.read_edgelist("test.edgelist", nodetype=int)
- >>> G=nx.read_edgelist("test.edgelist",create_using=nx.DiGraph)
+ >>> G = nx.read_edgelist("test.edgelist", nodetype=int)
+ >>> G = nx.read_edgelist("test.edgelist", create_using=nx.DiGraph)
Edgelist with data in a list:
- >>> textline = '1 2 3'
- >>> fh = open('test.edgelist','w')
+ >>> textline = "1 2 3"
+ >>> fh = open("test.edgelist", "w")
>>> d = fh.write(textline)
>>> fh.close()
- >>> G = nx.read_edgelist('test.edgelist', nodetype=int, data=(('weight',float),))
+ >>> G = nx.read_edgelist("test.edgelist", nodetype=int, data=(("weight", float),))
>>> list(G)
[1, 2]
>>> list(G.edges(data=True))
@@ -406,9 +400,9 @@ def write_weighted_edgelist(G, path, comments="#", delimiter=" ", encoding="utf-
Examples
--------
- >>> G=nx.Graph()
- >>> G.add_edge(1,2,weight=7)
- >>> nx.write_weighted_edgelist(G, 'test.weighted.edgelist')
+ >>> G = nx.Graph()
+ >>> G.add_edge(1, 2, weight=7)
+ >>> nx.write_weighted_edgelist(G, "test.weighted.edgelist")
See Also
--------
diff --git a/networkx/readwrite/gexf.py b/networkx/readwrite/gexf.py
index b69c4ae7..e3fe5a57 100644
--- a/networkx/readwrite/gexf.py
+++ b/networkx/readwrite/gexf.py
@@ -57,9 +57,9 @@ def write_gexf(G, path, encoding="utf-8", prettyprint=True, version="1.2draft"):
>>> nx.write_gexf(G, "test.gexf")
# visualization data
- >>> G.nodes[0]['viz'] = {'size': 54}
- >>> G.nodes[0]['viz']['position'] = {'x' : 0, 'y' : 1}
- >>> G.nodes[0]['viz']['color'] = {'r' : 0, 'g' : 0, 'b' : 256}
+ >>> G.nodes[0]["viz"] = {"size": 54}
+ >>> G.nodes[0]["viz"]["position"] = {"x": 0, "y": 1}
+ >>> G.nodes[0]["viz"]["color"] = {"r": 0, "g": 0, "b": 256}
Notes
@@ -103,10 +103,10 @@ def generate_gexf(G, encoding="utf-8", prettyprint=True, version="1.2draft"):
Examples
--------
>>> G = nx.path_graph(4)
- >>> linefeed = chr(10) # linefeed=\n
+ >>> linefeed = chr(10) # linefeed=\n
>>> s = linefeed.join(nx.generate_gexf(G)) # doctest: +SKIP
>>> for line in nx.generate_gexf(G): # doctest: +SKIP
- ... print(line)
+ ... print(line)
Notes
-----
diff --git a/networkx/readwrite/gml.py b/networkx/readwrite/gml.py
index 833665c5..ad31d479 100644
--- a/networkx/readwrite/gml.py
+++ b/networkx/readwrite/gml.py
@@ -162,8 +162,8 @@ def read_gml(path, label="label", destringizer=None):
Examples
--------
>>> G = nx.path_graph(4)
- >>> nx.write_gml(G, 'test.gml')
- >>> H = nx.read_gml('test.gml')
+ >>> nx.write_gml(G, "test.gml")
+ >>> H = nx.read_gml("test.gml")
"""
def filter_lines(lines):
diff --git a/networkx/readwrite/graph6.py b/networkx/readwrite/graph6.py
index 8111d965..a7517f85 100644
--- a/networkx/readwrite/graph6.py
+++ b/networkx/readwrite/graph6.py
@@ -83,7 +83,7 @@ def from_graph6_bytes(bytes_in):
Examples
--------
- >>> G = nx.from_graph6_bytes(b'A_')
+ >>> G = nx.from_graph6_bytes(b"A_")
>>> sorted(G.edges())
[(0, 1)]
@@ -205,7 +205,7 @@ def read_graph6(path):
>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
- ... _ = f.write(b'>>graph6<<A_\\n')
+ ... _ = f.write(b">>graph6<<A_\\n")
... _ = f.seek(0)
... G = nx.read_graph6(f.name)
>>> list(G.edges())
@@ -215,7 +215,7 @@ def read_graph6(path):
>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
- ... _ = f.write(b'>>graph6<<A_\\n')
+ ... _ = f.write(b">>graph6<<A_\\n")
... _ = f.seek(0)
... G = nx.read_graph6(f)
>>> list(G.edges())
diff --git a/networkx/readwrite/graphml.py b/networkx/readwrite/graphml.py
index 47b8d46d..520e857c 100644
--- a/networkx/readwrite/graphml.py
+++ b/networkx/readwrite/graphml.py
@@ -181,7 +181,7 @@ def generate_graphml(G, encoding="utf-8", prettyprint=True, named_key_ids=False)
>>> linefeed = chr(10) # linefeed = \n
>>> s = linefeed.join(nx.generate_graphml(G)) # doctest: +SKIP
>>> for line in nx.generate_graphml(G): # doctest: +SKIP
- ... print(line)
+ ... print(line)
Notes
-----
@@ -229,14 +229,14 @@ def read_graphml(path, node_type=str, edge_key_type=int, force_multigraph=False)
They can be obtained from `G.graph` and applied to node and edge attributes
if desired using something like this:
- >>> default_color = G.graph['node_default']['color'] # doctest: +SKIP
+ >>> default_color = G.graph["node_default"]["color"] # doctest: +SKIP
>>> for node, data in G.nodes(data=True): # doctest: +SKIP
- ... if 'color' not in data:
- ... data['color']=default_color
- >>> default_color = G.graph['edge_default']['color'] # doctest: +SKIP
+ ... if "color" not in data:
+ ... data["color"] = default_color
+ >>> default_color = G.graph["edge_default"]["color"] # doctest: +SKIP
>>> for u, v, data in G.edges(data=True): # doctest: +SKIP
- ... if 'color' not in data:
- ... data['color']=default_color
+ ... if "color" not in data:
+ ... data["color"] = default_color
This implementation does not support mixed graphs (directed and unidirected
edges together), hypergraphs, nested graphs, or ports.
@@ -310,14 +310,14 @@ def parse_graphml(
They can be obtained from `G.graph` and applied to node and edge attributes
if desired using something like this:
- >>> default_color = G.graph['node_default']['color'] # doctest: +SKIP
+ >>> default_color = G.graph["node_default"]["color"] # doctest: +SKIP
>>> for node, data in G.nodes(data=True): # doctest: +SKIP
- ... if 'color' not in data:
- ... data['color']=default_color
- >>> default_color = G.graph['edge_default']['color'] # doctest: +SKIP
+ ... if "color" not in data:
+ ... data["color"] = default_color
+ >>> default_color = G.graph["edge_default"]["color"] # doctest: +SKIP
>>> for u, v, data in G.edges(data=True): # doctest: +SKIP
- ... if 'color' not in data:
- ... data['color']=default_color
+ ... if "color" not in data:
+ ... data["color"] = default_color
This implementation does not support mixed graphs (directed and unidirected
edges together), hypergraphs, nested graphs, or ports.
diff --git a/networkx/readwrite/json_graph/adjacency.py b/networkx/readwrite/json_graph/adjacency.py
index ec6d21a4..cf7c8c72 100644
--- a/networkx/readwrite/json_graph/adjacency.py
+++ b/networkx/readwrite/json_graph/adjacency.py
@@ -36,7 +36,7 @@ def adjacency_data(G, attrs=_attrs):
Examples
--------
>>> from networkx.readwrite import json_graph
- >>> G = nx.Graph([(1,2)])
+ >>> G = nx.Graph([(1, 2)])
>>> data = json_graph.adjacency_data(G)
To serialize with json
@@ -110,7 +110,7 @@ def adjacency_graph(data, directed=False, multigraph=True, attrs=_attrs):
Examples
--------
>>> from networkx.readwrite import json_graph
- >>> G = nx.Graph([(1,2)])
+ >>> G = nx.Graph([(1, 2)])
>>> data = json_graph.adjacency_data(G)
>>> H = json_graph.adjacency_graph(data)
diff --git a/networkx/readwrite/json_graph/jit.py b/networkx/readwrite/json_graph/jit.py
index ccef18b6..77e9c1ee 100644
--- a/networkx/readwrite/json_graph/jit.py
+++ b/networkx/readwrite/json_graph/jit.py
@@ -95,9 +95,7 @@ def jit_data(G, indent=None, default=None):
if G[node]:
json_node["adjacencies"] = []
for neighbour in G[node]:
- adjacency = {
- "nodeTo": neighbour,
- }
+ adjacency = {"nodeTo": neighbour}
# adjacency data
adjacency["data"] = G.edges[node, neighbour]
json_node["adjacencies"].append(adjacency)
diff --git a/networkx/readwrite/json_graph/node_link.py b/networkx/readwrite/json_graph/node_link.py
index 42c4d07f..6ccc3b31 100644
--- a/networkx/readwrite/json_graph/node_link.py
+++ b/networkx/readwrite/json_graph/node_link.py
@@ -41,16 +41,20 @@ def node_link_data(G, attrs=None):
Examples
--------
>>> from networkx.readwrite import json_graph
- >>> G = nx.Graph([('A', 'B')])
+ >>> G = nx.Graph([("A", "B")])
>>> data1 = json_graph.node_link_data(G)
>>> H = nx.gn_graph(2)
- >>> data2 = json_graph.node_link_data(H, {'link': 'edges', 'source': 'from', 'target': 'to'})
+ >>> data2 = json_graph.node_link_data(
+ ... H, {"link": "edges", "source": "from", "target": "to"}
+ ... )
To serialize with json
>>> import json
>>> s1 = json.dumps(data1)
- >>> s2 = json.dumps(data2, default={'link': 'edges', 'source': 'from', 'target': 'to'})
+ >>> s2 = json.dumps(
+ ... data2, default={"link": "edges", "source": "from", "target": "to"}
+ ... )
Notes
-----
@@ -126,7 +130,7 @@ def node_link_graph(data, directed=False, multigraph=True, attrs=None):
Examples
--------
>>> from networkx.readwrite import json_graph
- >>> G = nx.Graph([('A', 'B')])
+ >>> G = nx.Graph([("A", "B")])
>>> data = json_graph.node_link_data(G)
>>> H = json_graph.node_link_graph(data)
diff --git a/networkx/readwrite/json_graph/tree.py b/networkx/readwrite/json_graph/tree.py
index 30ef1b53..665f35fc 100644
--- a/networkx/readwrite/json_graph/tree.py
+++ b/networkx/readwrite/json_graph/tree.py
@@ -40,8 +40,8 @@ def tree_data(G, root, attrs=_attrs):
Examples
--------
>>> from networkx.readwrite import json_graph
- >>> G = nx.DiGraph([(1,2)])
- >>> data = json_graph.tree_data(G,root=1)
+ >>> G = nx.DiGraph([(1, 2)])
+ >>> data = json_graph.tree_data(G, root=1)
To serialize with json
@@ -110,8 +110,8 @@ def tree_graph(data, attrs=_attrs):
Examples
--------
>>> from networkx.readwrite import json_graph
- >>> G = nx.DiGraph([(1,2)])
- >>> data = json_graph.tree_data(G,root=1)
+ >>> G = nx.DiGraph([(1, 2)])
+ >>> data = json_graph.tree_data(G, root=1)
>>> H = json_graph.tree_graph(data)
Notes
diff --git a/networkx/readwrite/multiline_adjlist.py b/networkx/readwrite/multiline_adjlist.py
index fb558c01..e12f9007 100644
--- a/networkx/readwrite/multiline_adjlist.py
+++ b/networkx/readwrite/multiline_adjlist.py
@@ -152,18 +152,18 @@ def write_multiline_adjlist(G, path, delimiter=" ", comments="#", encoding="utf-
Examples
--------
- >>> G=nx.path_graph(4)
- >>> nx.write_multiline_adjlist(G,"test.adjlist")
+ >>> G = nx.path_graph(4)
+ >>> nx.write_multiline_adjlist(G, "test.adjlist")
The path can be a file handle or a string with the name of the file. If a
file handle is provided, it has to be opened in 'wb' mode.
- >>> fh=open("test.adjlist",'wb')
- >>> nx.write_multiline_adjlist(G,fh)
+ >>> fh = open("test.adjlist", "wb")
+ >>> nx.write_multiline_adjlist(G, fh)
Filenames ending in .gz or .bz2 will be compressed.
- >>> nx.write_multiline_adjlist(G,"test.adjlist.gz")
+ >>> nx.write_multiline_adjlist(G, "test.adjlist.gz")
See Also
--------
@@ -216,11 +216,13 @@ def parse_multiline_adjlist(
Examples
--------
- >>> lines = ['1 2',
- ... "2 {'weight':3, 'name': 'Frodo'}",
- ... "3 {}",
- ... "2 1",
- ... "5 {'weight':6, 'name': 'Saruman'}"]
+ >>> lines = [
+ ... "1 2",
+ ... "2 {'weight':3, 'name': 'Frodo'}",
+ ... "3 {}",
+ ... "2 1",
+ ... "5 {'weight':6, 'name': 'Saruman'}",
+ ... ]
>>> G = nx.parse_multiline_adjlist(iter(lines), nodetype=int)
>>> list(G)
[1, 2, 3, 5]
@@ -329,39 +331,39 @@ def read_multiline_adjlist(
Examples
--------
- >>> G=nx.path_graph(4)
- >>> nx.write_multiline_adjlist(G,"test.adjlist")
- >>> G=nx.read_multiline_adjlist("test.adjlist")
+ >>> G = nx.path_graph(4)
+ >>> nx.write_multiline_adjlist(G, "test.adjlist")
+ >>> G = nx.read_multiline_adjlist("test.adjlist")
The path can be a file or a string with the name of the file. If a
file s provided, it has to be opened in 'rb' mode.
- >>> fh=open("test.adjlist", 'rb')
- >>> G=nx.read_multiline_adjlist(fh)
+ >>> fh = open("test.adjlist", "rb")
+ >>> G = nx.read_multiline_adjlist(fh)
Filenames ending in .gz or .bz2 will be compressed.
- >>> nx.write_multiline_adjlist(G,"test.adjlist.gz")
- >>> G=nx.read_multiline_adjlist("test.adjlist.gz")
+ >>> nx.write_multiline_adjlist(G, "test.adjlist.gz")
+ >>> G = nx.read_multiline_adjlist("test.adjlist.gz")
The optional nodetype is a function to convert node strings to nodetype.
For example
- >>> G=nx.read_multiline_adjlist("test.adjlist", nodetype=int)
+ >>> G = nx.read_multiline_adjlist("test.adjlist", nodetype=int)
will attempt to convert all nodes to integer type.
The optional edgetype is a function to convert edge data strings to
edgetype.
- >>> G=nx.read_multiline_adjlist("test.adjlist")
+ >>> G = nx.read_multiline_adjlist("test.adjlist")
The optional create_using parameter is a NetworkX graph container.
The default is Graph(), an undirected graph. To read the data as
a directed graph use
- >>> G=nx.read_multiline_adjlist("test.adjlist", create_using=nx.DiGraph)
+ >>> G = nx.read_multiline_adjlist("test.adjlist", create_using=nx.DiGraph)
Notes
-----
diff --git a/networkx/readwrite/nx_shp.py b/networkx/readwrite/nx_shp.py
index 3ff68192..c1f4ce82 100644
--- a/networkx/readwrite/nx_shp.py
+++ b/networkx/readwrite/nx_shp.py
@@ -69,7 +69,7 @@ def read_shp(path, simplify=True, geom_attrs=True, strict=True):
Examples
--------
- >>> G = nx.read_shp('test.shp') # doctest: +SKIP
+ >>> G = nx.read_shp("test.shp") # doctest: +SKIP
References
----------
diff --git a/networkx/readwrite/nx_yaml.py b/networkx/readwrite/nx_yaml.py
index 9d6719f3..a8b76380 100644
--- a/networkx/readwrite/nx_yaml.py
+++ b/networkx/readwrite/nx_yaml.py
@@ -41,8 +41,8 @@ def write_yaml(G_to_be_yaml, path_for_yaml_output, **kwds):
Examples
--------
- >>> G=nx.path_graph(4)
- >>> nx.write_yaml(G,'test.yaml')
+ >>> G = nx.path_graph(4)
+ >>> nx.write_yaml(G, "test.yaml")
References
----------
@@ -74,9 +74,9 @@ def read_yaml(path):
Examples
--------
- >>> G=nx.path_graph(4)
- >>> nx.write_yaml(G,'test.yaml')
- >>> G=nx.read_yaml('test.yaml')
+ >>> G = nx.path_graph(4)
+ >>> nx.write_yaml(G, "test.yaml")
+ >>> G = nx.read_yaml("test.yaml")
References
----------
diff --git a/networkx/readwrite/sparse6.py b/networkx/readwrite/sparse6.py
index 215d4b5a..f9ea9bb7 100644
--- a/networkx/readwrite/sparse6.py
+++ b/networkx/readwrite/sparse6.py
@@ -120,7 +120,7 @@ def from_sparse6_bytes(string):
Examples
--------
- >>> G = nx.from_sparse6_bytes(b':A_')
+ >>> G = nx.from_sparse6_bytes(b":A_")
>>> sorted(G.edges())
[(0, 1), (0, 1), (0, 1)]
@@ -273,7 +273,7 @@ def read_sparse6(path):
>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
- ... _ = f.write(b'>>sparse6<<:An\\n')
+ ... _ = f.write(b">>sparse6<<:An\\n")
... _ = f.seek(0)
... G = nx.read_sparse6(f.name)
>>> list(G.edges())
@@ -283,7 +283,7 @@ def read_sparse6(path):
>>> import tempfile
>>> with tempfile.NamedTemporaryFile() as f:
- ... _ = f.write(b'>>sparse6<<:An\\n')
+ ... _ = f.write(b">>sparse6<<:An\\n")
... _ = f.seek(0)
... G = nx.read_sparse6(f)
>>> list(G.edges())
diff --git a/networkx/readwrite/tests/test_gml.py b/networkx/readwrite/tests/test_gml.py
index 9ef3dd36..d18b5948 100644
--- a/networkx/readwrite/tests/test_gml.py
+++ b/networkx/readwrite/tests/test_gml.py
@@ -589,7 +589,7 @@ class TestPropertyLists:
)
f.seek(0)
graph = nx.read_gml(f)
- assert graph.nodes(data=True)["n1"] == {"properties": ["element", 0, 1, 2.5,]}
+ assert graph.nodes(data=True)["n1"] == {"properties": ["element", 0, 1, 2.5]}
def test_reading_graph_with_single_element_list_property(self):
with byte_file() as f:
@@ -609,4 +609,4 @@ class TestPropertyLists:
)
f.seek(0)
graph = nx.read_gml(f)
- assert graph.nodes(data=True)["n1"] == {"properties": ["element",]}
+ assert graph.nodes(data=True)["n1"] == {"properties": ["element"]}
diff --git a/networkx/readwrite/tests/test_graphml.py b/networkx/readwrite/tests/test_graphml.py
index 39ea907d..7b90791f 100644
--- a/networkx/readwrite/tests/test_graphml.py
+++ b/networkx/readwrite/tests/test_graphml.py
@@ -202,9 +202,7 @@ class BaseGraphML:
cls.simple_undirected_graph = nx.Graph()
cls.simple_undirected_graph.add_node("n10")
cls.simple_undirected_graph.add_edge("n0", "n2", id="foo")
- cls.simple_undirected_graph.add_edges_from(
- [("n1", "n2"), ("n2", "n3"),]
- )
+ cls.simple_undirected_graph.add_edges_from([("n1", "n2"), ("n2", "n3")])
fh = io.BytesIO(cls.simple_undirected_data.encode("UTF-8"))
cls.simple_undirected_fh = fh