[Numpy-discussion] Question about improving genfromtxt errors

Skipper Seabold jsseabold@gmail....
Fri Sep 25 12:00:07 CDT 2009


There have been some recent attempts to improve the error reporting in
genfromtxt <http://projects.scipy.org/numpy/ticket/1212>, which is
great, because hunting down the problems reading in big and messy
files is not fun.

I am working on a patch that keeps up with the line number and column
number of where you are in parsing the file, so that this can be
reported in the error.  Is there a way to catch a raised error and add
to it?

For instance, I have a problem in my file which leads to this error
being raised from np.lib._iotools.StringCoverter.upgrade

ValueError: Converter is locked and cannot be upgraded

I added this into np.lib.io.genfromtxt around line 995.

linenum = 0
[...]
if dtype is None:
            try:
                colnum = 0
                for (converter, item) in zip(converters, values):
                    converter.upgrade(item)
                    colnum += 1
            except:
                raise ValueError, "I don't report the error from
_iotools.StringConverter.upgrade, but I do know that there is a
problem trying to convert a value at line %s and column %s" %
(linenum,colnum)
[...]
linenum += 1

I'd like to add line and column number information to original error
from _iotools.  Any suggestions?

Cheers,
Skipper


More information about the NumPy-Discussion mailing list