[Numpy-discussion] major bug in fromstring, ascii mode
Eric Firing
efiring at hawaii.edu
Mon Jan 28 20:26:41 EST 2008
Charles R Harris wrote:
>
>
> On Jan 28, 2008 4:09 PM, Eric Firing <efiring at hawaii.edu
> <mailto:efiring at hawaii.edu>> wrote:
>
> Charles R Harris wrote:
>
> > Reading the code in arraytypes.inc.src and multiarraymodule.c, it
> > appears that numpy is using strtol(str, &tailptr, 0) for the
> string to
> > integer conversion. Calling strtol with BASE == 0 enables the
> automatic
> > base detection from the prefix.
> >
> > However, as you say, scanf does not do this. Numpy appears to
> use fscanf
> > when reading data from files, so there is a discrepancy here:
> >
> > >>> from numpy import fromfile, fromstring
> > >>> f = open('test.dat', 'w')
> > >>> f.write("20:09:21")
> > >>> f.close()
> >
> > >>> fromfile('test.dat', dtype=int, sep=':')
> > array([20, 9, 21])
> > >>> fromstring('20:09:21', dtype=int, sep=':')
> > array([20, 0])
> >
> >
> > I vote for fromstring working like fromfile.
>
> I agree. Can we get this change into 1.05? I could make a patch if
> that would help. Although I was wrong in calling this a "major bug", I
> think it is an inconsistency that should be removed. The fromfile and
> fromstring docstrings could also state explicitly what the behavior is.
>
>
> Your best bet is to file a ticket. I you don't, I will, but I'll wait a bit.
It is ticket #650.
Eric
More information about the NumPy-Discussion
mailing list