summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/user/basics.io.genfromtxt.rst5
-rw-r--r--numpy/lib/npyio.py7
-rw-r--r--numpy/lib/tests/test_io.py7
3 files changed, 15 insertions, 4 deletions
diff --git a/doc/source/user/basics.io.genfromtxt.rst b/doc/source/user/basics.io.genfromtxt.rst
index 2bdd5a0d0..17774eeeb 100644
--- a/doc/source/user/basics.io.genfromtxt.rst
+++ b/doc/source/user/basics.io.genfromtxt.rst
@@ -133,13 +133,16 @@ marker(s) is simply ignored::
[ 7. 8.]
[ 9. 0.]]
+.. versionadded:: 1.7.0
+
+ When ``comments`` is set to ``None``, no lines are treated as comments.
+
.. note::
There is one notable exception to this behavior: if the optional argument
``names=True``, the first commented line will be examined for names.
-
Skipping lines and choosing columns
===================================
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 197562818..29688f73d 100644
--- 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:
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 7dcefe80d..84aca9915 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1317,6 +1317,13 @@ M 33 21.99
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')