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:
Here's a minimal reproducing example:

```python
>>> import networkx as nx
>>> edge_list = ['1, 2, {"weight": 1, "color": "green"}']
>>> G = nx.parse_edgelist(edge_list, delimiter=',')
Traceback (most recent call last)
   ...
IndentationError
   ...
TypeError: Failed to convert edge data ([' {"weight": 1', ' "color": "green"}']) to dictionary.
```

Side note: this seems like a good candidate for for `from None` instead of `from e` in the exception raising as the `IndentationError` is confusing.

Resolving patch:
diff --git a/networkx/readwrite/edgelist.py b/networkx/readwrite/edgelist.py
--- 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
--- a/networkx/readwrite/tests/test_edgelist.py
+++ b/networkx/readwrite/tests/test_edgelist.py
@@ -100,6 +100,48 @@ def test_read_edgelist_4(self):
             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()