[Numpy-discussion] formatting issues, locale and co

David Cournapeau cournape@gmail....
Tue Dec 30 22:11:02 CST 2008


On Wed, Dec 31, 2008 at 11:28 AM, Pauli Virtanen <pav@iki.fi> wrote:
> Mon, 29 Dec 2008 13:38:12 +0900, David Cournapeau wrote:
> [clip]
>> I put my yesterday work in the fix_float_format branch:
>>  - it fixes the locale issue
>>  - it fixes the long double issue on windows.
>>  - it also fixes some tests (we were not testing single precision
>>    formatting but twice double precision instead
>>  - the single precision test fails on the trunk BTW).
>>  - it handles inf and nan more consistently across platforms (e.g.
>>    str(np.log(0)) will be '-inf' on all platforms; on windows, it used
>>    to be '-1.#INF'
>>  - I was afraid it would broke converting back the
>>    string to float, but it is broken anyway before my change, e.g.
>>    float('-1.#INF') does not work on windows).
> [clip]
>
> I did some work on the fix_float_format branch from the opposite
> direction, making fromfile and fromstring properly locale-independent.
> (cf. #884)
>
> Works currently on POSIX systems, but some tests fail on Windows because
> float('inf') does not work [neither does float('-1.#INF')...]. (cf. #510)
> A bit more work must be done on NumPyOS_ascii_strtod to make inf/nan work
> as intended. Also, roundtrip tests for repr would be nice to add, if they
> aren't there yet, and possibly for str <-> fromstring roundtrip, too.
> I'll be almost offline for 1.5 weeks starting now, so if you want to
> finish this, go ahead.

Thank you for working on this, Pauli. The problem on windows may not
be specific to windows: the difference really is whether the
formatting is done by python or the C runtime. It just happens that on
Linux and Mac OS X, the strings are the same - but it could be
different on other OS. I have not looked into C99, whether this is
standardized or not (the size of exponent is, but I don't know about
nan and inf).

We should also change pretty print of arrays, I think - although it is
a change and may break things. Since that's how python represents the
numbers, I guess we will have to change at some point.

David


More information about the Numpy-discussion mailing list