Repository: networkx/networkx

Issue:
read_edgelist not reading all lines of write_edgelist file
<!-- If you have a general question about NetworkX, please use the discussions tab to create a new discussion -->

<!--- Provide a general summary of the issue in the Title above -->

For a graph analysis I am doing, I am using nx.write_edgelist(G,path=path) to write to the following file.

[A2_early_0.04.15.txt](https://github.com/networkx/networkx/files/6893893/A2_early_0.04.15.txt)

However, reading this data through nx.readwrite.edgelist.read_edgelist(filename, create_using=nx.DiGraph()) 
causes a problem, as not all data is read. 

### Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
Reads in 617 edges of the above adjacency list


### Expected Behavior
<!--- Tell us what should happen -->
Expect to read all 780 edges

### Steps to Reproduce
<!--- Provide a minimal example that reproduces the bug -->

G = nx.readwrite.edgelist.read_edgelist(filename, create_using=nx.DiGraph()) 
print(G.number_of_edges)

### Environment
<!--- Please provide details about your local environment -->
Python version: 3.8.5
NetworkX version: 2.5.1


### Additional context
<!--- Add any other context about the problem here, screenshots, etc. -->



Discussion:
Hi @arav-agarwal2, it looks like your file contains quite a few lines with `#` characters.  By default, those are treated as comments in `read_edgelist`.  This can be fixed by setting the `comments` parameter to a string that doesn't occur in the file, or to be a little sneaky,`'\n'`:

```
G = nx.readwrite.edgelist.read_edgelist(filename, create_using=nx.DiGraph(), comments='\n')
```
Excellent catch @boothby - this is indeed what is happening with this particular data file.

On a related note, maybe `comments` should be made an optional kwarg with the ability to pass in `comments=None` to indicate that there is no comment character, rather than making the user get creative with their comment character selection. Thoughts?

Resolving patch:
diff --git a/networkx/readwrite/edgelist.py b/networkx/readwrite/edgelist.py
--- a/networkx/readwrite/edgelist.py
+++ b/networkx/readwrite/edgelist.py
@@ -183,7 +183,8 @@ def parse_edgelist(
     lines : list or iterator of strings
         Input data in edgelist format
     comments : string, optional
-       Marker for comment lines. Default is `'#'`
+       Marker for comment lines. Default is `'#'`. To specify that no character
+       should be treated as a comment, use ``comments=None``.
     delimiter : string, optional
        Separator for node labels. Default is `None`, meaning any whitespace.
     create_using : NetworkX graph constructor, optional (default=nx.Graph)
@@ -238,11 +239,12 @@ def parse_edgelist(
 
     G = nx.empty_graph(0, create_using)
     for line in lines:
-        p = line.find(comments)
-        if p >= 0:
-            line = line[:p]
-        if not line:
-            continue
+        if comments is not None:
+            p = line.find(comments)
+            if p >= 0:
+                line = line[:p]
+            if not line:
+                continue
         # split line, should have 2 or more
         s = line.strip().split(delimiter)
         if len(s) < 2:
@@ -314,7 +316,8 @@ def read_edgelist(
        opened in 'rb' mode.
        Filenames ending in .gz or .bz2 will be uncompressed.
     comments : string, optional
-       The character used to indicate the start of a comment.
+       The character used to indicate the start of a comment. To specify that
+       no character should be treated as a comment, use ``comments=None``.
     delimiter : string, optional
        The string used to separate values.  The default is whitespace.
     create_using : NetworkX graph constructor, optional (default=nx.Graph)


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
@@ -161,6 +161,14 @@ def test_parse_edgelist():
         nx.parse_edgelist(lines, nodetype=int, data=(("weight", float),))
 
 
+def test_comments_None():
+    edgelist = ["node#1 node#2", "node#2 node#3"]
+    # comments=None supported to ignore all comment characters
+    G = nx.parse_edgelist(edgelist, comments=None)
+    H = nx.Graph([e.split(" ") for e in edgelist])
+    assert edges_equal(G.edges, H.edges)
+
+
 class TestEdgelist:
     @classmethod
     def setup_class(cls):