summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authorRaunak Shah <32986603+raunaks13@users.noreply.github.com>2018-04-17 05:12:01 +0000
committerEric Wieser <wieser.eric@gmail.com>2018-04-16 22:12:01 -0700
commit8323be1bc44c2811fc36f5b99c1a30ebcee8edbd (patch)
treece7a026aa95f62b2fc557d6573367b8022d9bb42 /numpy/lib/npyio.py
parent3b79c4405690227087022a943fd78217b700a3f5 (diff)
downloadnumpy-8323be1bc44c2811fc36f5b99c1a30ebcee8edbd.tar.gz
BUG: fix crash in numpy.genfromtxt(..., names=True, comments=None) (#10822)
Fixes gh-10780
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py7
1 files changed, 4 insertions, 3 deletions
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: