Repository: networkx/networkx

Issue:
Parse edgelist bug
When calling `parse_edgelist()` using comma delimiters, it will fail to parse correctly fro edges with multiple attributes.

Ex. of bad edge:
`1,2,{'test':1, 'test_other':2}`

`parse_edgelist()` will recognize the comma in the braces as delimiter and try to split them up.

Discussion:
pep8speaks: Hello @crsqq! Thanks for opening this PR. 



* In the file [`networkx/readwrite/tests/test_edgelist.py`](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py):

> [Line 117:17](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L117): [E126](https://duckduckgo.com/?q=pep8%20E126) continuation line over-indented for hanging indent
> [Line 117:68](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L117): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ':'
> [Line 118:21](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L118): [E128](https://duckduckgo.com/?q=pep8%20E128) continuation line under-indented for visual indent
> [Line 118:51](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L118): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ':'
> [Line 121:5](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L121): [F811](https://duckduckgo.com/?q=pep8%20F811) redefinition of unused 'test_read_edgelist_5' from line 103
> [Line 135:17](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L135): [E126](https://duckduckgo.com/?q=pep8%20E126) continuation line over-indented for hanging indent
> [Line 135:68](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L135): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ':'
> [Line 136:21](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L136): [E128](https://duckduckgo.com/?q=pep8%20E128) continuation line under-indented for visual indent
> [Line 136:51](https://github.com/networkx/networkx/blob/cca13b9f799689e9aa1fa9323b5ef0bc94445396/networkx/readwrite/tests/test_edgelist.py#L136): [E231](https://duckduckgo.com/?q=pep8%20E231) missing whitespace after ':'

Please install and run [psf/black](https://github.com/psf/black).

Patch:
diff --git a/networkx/readwrite/edgelist.py b/networkx/readwrite/edgelist.py
index 72afe1a7c..5183071d1 100644
--- a/networkx/readwrite/edgelist.py
+++ b/networkx/readwrite/edgelist.py
@@ -270,7 +270,11 @@ def parse_edgelist(
         elif data is True:
             # no edge types specified
             try:  # try to evaluate as dictionary
-                edgedata = dict(literal_eval(" ".join(d)))
+                if delimiter == ",":
+                    edgedata_str = ",".join(d)
+                else:
+                    edgedata_str = " ".join(d)
+                edgedata = dict(literal_eval(edgedata_str.strip()))
             except BaseException as e:
                 raise TypeError(
                     f"Failed to convert edge data ({d}) " f"to dictionary."


Test patch:
diff --git a/networkx/readwrite/tests/test_edgelist.py b/networkx/readwrite/tests/test_edgelist.py
index 2e1a2424f..31f214566 100644
--- a/networkx/readwrite/tests/test_edgelist.py
+++ b/networkx/readwrite/tests/test_edgelist.py
@@ -100,6 +100,48 @@ class TestEdgelist:
             G.edges(data=True), [(1, 2, {"weight": 2.0}), (2, 3, {"weight": 3.0})]
         )
 
+    def test_read_edgelist_5(self):
+        s = b"""\
+# comment line
+1 2 {'weight':2.0, 'color':'green'}
+# comment line
+2 3 {'weight':3.0, 'color':'red'}
+"""
+        bytesIO = io.BytesIO(s)
+        G = nx.read_edgelist(bytesIO, nodetype=int, data=False)
+        assert_edges_equal(G.edges(), [(1, 2), (2, 3)])
+
+        bytesIO = io.BytesIO(s)
+        G = nx.read_edgelist(bytesIO, nodetype=int, data=True)
+        assert_edges_equal(
+            G.edges(data=True),
+            [
+                (1, 2, {"weight": 2.0, "color": "green"}),
+                (2, 3, {"weight": 3.0, "color": "red"}),
+            ],
+        )
+
+    def test_read_edgelist_6(self):
+        s = b"""\
+# comment line
+1, 2, {'weight':2.0, 'color':'green'}
+# comment line
+2, 3, {'weight':3.0, 'color':'red'}
+"""
+        bytesIO = io.BytesIO(s)
+        G = nx.read_edgelist(bytesIO, nodetype=int, data=False, delimiter=",")
+        assert_edges_equal(G.edges(), [(1, 2), (2, 3)])
+
+        bytesIO = io.BytesIO(s)
+        G = nx.read_edgelist(bytesIO, nodetype=int, data=True, delimiter=",")
+        assert_edges_equal(
+            G.edges(data=True),
+            [
+                (1, 2, {"weight": 2.0, "color": "green"}),
+                (2, 3, {"weight": 3.0, "color": "red"}),
+            ],
+        )
+
     def test_write_edgelist_1(self):
         fh = io.BytesIO()
         G = nx.OrderedGraph()