diff options
author | Daniel da Silva <daniel@meltingwax.net> | 2014-04-04 23:48:58 -0400 |
---|---|---|
committer | Daniel da Silva <daniel@meltingwax.net> | 2014-04-05 14:39:35 -0400 |
commit | 079ca4d2da488ffb7af1fc923728c3abde867231 (patch) | |
tree | ef28ee1f3d849e3c71f2fe8fd7c6f95ef86c8492 /numpy/lib/npyio.py | |
parent | a0794f63d548e688e2eed76a9dc4e8df0ea33846 (diff) | |
download | numpy-079ca4d2da488ffb7af1fc923728c3abde867231.tar.gz |
ENH: Better error w/ line num for bad column count in np.loadtxt()
Resolves #2591. Adds more explicit error handling in line parsing loop.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index f69ca0c73..98b4b6e35 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -845,6 +845,11 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, continue if usecols: vals = [vals[i] for i in usecols] + if len(vals) != N: + line_num = i + skiprows + 1 + raise ValueError("Wrong number of columns at line %d" + % line_num) + # Convert each value according to its column and store items = [conv(val) for (conv, val) in zip(converters, vals)] # Then pack it according to the dtype's nesting |