Repository: numpy/numpy

Issue:
In genfromtxt(), comments=None raises error with names=True
Sorry in advance if this is a duplicate. As of numpy 1.12.1,  an error is raised by genfromtxt() when using `names=True` with `comments=None`. Tested with:
* Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 16 2017, 17:29:19) 
* numpy 1.12.1
* Linux rsiverd-linux.lco.gtn 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

...............................................................................................................

**Instructions to reproduce** (using attached sample file 'asdf.txt'):
```
data = np.genfromtxt('asdf.txt', dtype=None, comments=None, delimiter='|', names=True)
```
[asdf.txt](https://github.com/numpy/numpy/files/1835574/asdf.txt)
...............................................................................................................
**Expected result**: 
* Successful loading of the data file (no error).

...............................................................................................................
**Actual result**:
```
TypeError                                 Traceback (most recent call last)
<ipython-input-1-1d47ac60e22b> in <module>()
----> 1 data = np.genfromtxt('asdf.txt', dtype=None, comments=None, delimiter='|', names=True)

/home/rsiverd/anaconda2/lib/python2.7/site-packages/numpy/lib/npyio.pyc in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows)
   1536             first_line = next(fhd)
   1537             if names is True:
-> 1538                 if comments in first_line:
   1539                     first_line = (
   1540                         asbytes('').join(first_line.split(comments)[1:]))

TypeError: 'in <string>' requires string as left operand, not NoneType
```

...............................................................................................................
**Suggested remedy:**

It looks like the check for the first valid values does not check whether `comments is None` before looking for the comment string in the first line, raising this error. I suspect this is easily fixed by replacing
```
        while not first_values:
            first_line = next(fhd)
            if names is True:
                if comments in first_line:
                    first_line = (
                        asbytes('').join(first_line.split(comments)[1:]))
            first_values = split_line(first_line)
```
with
```
        while not first_values:
            first_line = next(fhd)
            if (names is True) and (comments is not None):
                if comments in first_line:
                    first_line = (
                        asbytes('').join(first_line.split(comments)[1:]))
            first_values = split_line(first_line)
```



Discussion:
Could I work on this?
No objection from me. I am traveling and would not have an opportunity to look at this for a few weeks ...

Resolving patch:
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1720,7 +1720,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
     try:
         while not first_values:
             first_line = _decode_line(next(fhd), encoding)
-            if names is True:
+            if (names is True) and (comments is not None):
                 if comments in first_line:
                     first_line = (
                         ''.join(first_line.split(comments)[1:]))
@@ -1734,8 +1734,9 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
     # Should we take the first values as names ?
     if names is True:
         fval = first_values[0].strip()
-        if fval in comments:
-            del first_values[0]
+        if comments is not None:
+            if fval in comments:
+                del first_values[0]
 
     # Check the columns to use: make sure `usecols` is a list
     if usecols is not None:


Test patch:
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1317,6 +1317,13 @@ def test_commented_header(self):
             assert_(w[0].category is np.VisibleDeprecationWarning)
         assert_equal(test, ctrl)
 
+    def test_names_and_comments_none(self):
+        # Tests case when names is true but comments is None (gh-10780)
+        data = TextIO('col1 col2\n 1 2\n 3 4')
+        test = np.genfromtxt(data, dtype=(int, int), comments=None, names=True)
+        control = np.array([(1, 2), (3, 4)], dtype=[('col1', int), ('col2', int)])
+        assert_equal(test, control)
+
     def test_autonames_and_usecols(self):
         # Tests names and usecols
         data = TextIO('A B C D\n aaaa 121 45 9.1')