[Numpy-tickets] [NumPy] #650: fromfile and fromstring differ in parsing ascii integer strings
NumPy
numpy-tickets@scipy....
Mon Jan 28 19:24:49 CST 2008
#650: fromfile and fromstring differ in parsing ascii integer strings
------------------------+---------------------------------------------------
Reporter: efiring | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.0.5
Component: numpy.core | Version: none
Severity: normal | Keywords:
------------------------+---------------------------------------------------
When parsing ascii with an integer dtype specified, fromfile uses fscanf
with a format string that assumes base-10, while fromstring uses
PyOS_strtol with its third parameter, base, set to 0. This causes auto-
detection of the base, allowing hex and octal to be recognized
automatically. The disadvantages are that this can cause the same string
to be parsed differently by fromfile and fromstring, and that in common
cases, such as parsing a date or time string, the leading 0 triggers
unwanted interpretation of a number as octal (which can fail outright)
when it is actually base-10.
{{{
In [2]:numpy.fromstring("12:09:09", dtype=int, sep=':')
Out[2]:array([12, 0])
}}}
Changing the base argument to PyOS_strtol from 0 to 10 in
arraytypes.inc.src would change the behavior of fromstring to match that
of fromfile and eliminate the surprising behavior illustrated above.
This has been discussed in the thread
[http://thread.gmane.org/gmane.comp.python.numeric.general/18630]
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/650>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list