[Numpy-discussion] fromfile() -- help!

Christopher Barker Chris.Barker at noaa.gov
Thu Jan 7 20:21:34 EST 2010


I'm trying to dig into the code and figure out how to get it to stop 
putting in zeros for missing data with fromfile()/fromstring() text reading.

It looks like the culprit is this, in arraytypes.c.src:

@fname at _scan(FILE *fp, @type@ *ip, void *NPY_UNUSED(ignore), 
PyArray_Descr *NPY_UNUSED(ignored))
     double result;
     int ret;

     ret = NumPyOS_ascii_ftolf(fp, &result);
     *ip = (@type@) result;
     return ret;

If I'm reading this right, this gets called for the datatype of 
interest, and it is passed in a pointer to the file that is being read.

if I have NumPyOS_ascii_ftolf right, it should return 0 if it doesn't 
succesfully read a number. However, this looks like it sets the data in 
*ip, even if the return value is zero.

It does pass on that return value, but, from ctors.c:

fromfile_next_element(FILE **fp, void *dptr, PyArray_Descr *dtype,
                       void *NPY_UNUSED(stream_data))
     /* the NULL argument is for backwards-compatibility */
     return dtype->f->scanfunc(*fp, dptr, NULL, dtype);

just moves it on through. This is called from here:

         if (next(&stream, dptr, dtype, stream_data) < 0) {

which is checking for < 0 , so if a zero is returned, it will just go in 
its merry way...

So, have I got that right?

Should this get fixed at that last point?

One more point, this is a bit different for fromfile and fromstring, so 
I'm getting really confused!


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov

More information about the NumPy-Discussion mailing list