Re: Encoding NaN in JSON

2013-04-20 Thread Chris “Kwpolska” Warrick
On Fri, Apr 19, 2013 at 9:42 PM, Grant Edwards invalid@invalid.invalid wrote: The OP asked for a string, and I thought you were proposing the string 'null'. If one is to use a string, then 'NaN' makes the most sense, since it can be converted back into a floating point NaN object. I infer

Re: Encoding NaN in JSON

2013-04-19 Thread Robert Kern
On 2013-04-19 10:34, Tim Roberts wrote: Miki Tebeka miki.teb...@gmail.com wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N

Re: Encoding NaN in JSON

2013-04-19 Thread Grant Edwards
On 2013-04-18, Wayne Werner wa...@waynewerner.com wrote: On Wed, 17 Apr 2013, Miki Tebeka wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit

Re: Encoding NaN in JSON

2013-04-19 Thread Chris “Kwpolska” Warrick
On Fri, Apr 19, 2013 at 4:54 PM, Grant Edwards invalid@invalid.invalid wrote: On 2013-04-18, Wayne Werner wa...@waynewerner.com wrote: On Wed, 17 Apr 2013, Miki Tebeka wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's

Re: Encoding NaN in JSON

2013-04-19 Thread Grant Edwards
float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. Why not use `null` instead? It seems to be semantically more similar... Why not use 'NaN' instead? It seems

Re: Encoding NaN in JSON

2013-04-19 Thread Miki Tebeka
You understand that this will result in a chunk of text that is not JSON? I think he means something like this: json.dumps([float('nan')]) '[N/A]' That's exactly what I mean :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-18 Thread Roland Koebler
On Thu, Apr 18, 2013 at 11:46:37AM +1000, Chris Angelico wrote: Wait... you can do that? It's internal to iterencode, at least in Python 3.3 and 2.7 that I'm looking at here. In Python 2.6 it wasn't internal to iterencode; in Python 2.7 and 3.x you probably would have to monkey-patch iterencode.

Re: Encoding NaN in JSON

2013-04-18 Thread Wayne Werner
On Wed, 17 Apr 2013, Miki Tebeka wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. Why not use `null` instead

Re: Encoding NaN in JSON

2013-04-18 Thread Tim Roberts
Miki Tebeka miki.teb...@gmail.com wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. You understand

Re: Encoding NaN in JSON

2013-04-17 Thread Miki Tebeka
I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-17 Thread John Gordon
In c37a3b9c-6fe8-48aa-b703-9b4f922c3...@googlegroups.com Miki Tebeka miki.teb...@gmail.com writes: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit

Re: Encoding NaN in JSON

2013-04-17 Thread Johann Hibschman
Miki Tebeka miki.teb...@gmail.com writes: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string* 'N/A' for every NaN. Easiest way is probably

Re: Encoding NaN in JSON

2013-04-17 Thread Miki Tebeka
I'm trying to find a way to have json emit float('NaN') as 'N/A'. Easiest way is probably to transform your object before you try to write Yeah, that's what I ended up doing. Wondered if there's a better way ... Thanks, -- Miki -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-17 Thread Dave Angel
On 04/17/2013 03:05 PM, Johann Hibschman wrote: Miki Tebeka miki.teb...@gmail.com writes: I'm trying to find a way to have json emit float('NaN') as 'N/A'. No. There is no way to represent NaN in JSON. It's simply not part of the specification. I know that. I'm trying to emit the *string

Re: Encoding NaN in JSON

2013-04-17 Thread Roland Koebler
): if some-check-if-obj-is-NaN: return 'NaN' return json.JSONEncoder.default(self, obj) Roland -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-17 Thread Miki Tebeka
[Roland] yes, there is: subclass+extend the JSON-encoder, see pydoc json. Please read the original post before answering. What you suggested does not work since NaN is of float type. -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-17 Thread Roland Koebler
Hi, yes, there is: subclass+extend the JSON-encoder, see pydoc json. Please read the original post before answering. What you suggested does not work since NaN is of float type. ok, right, default does not work this way. But I would still suggest to extend the JSON-encoder, since

Re: Encoding NaN in JSON

2013-04-17 Thread Chris Angelico
On Thu, Apr 18, 2013 at 11:01 AM, Miki Tebeka miki.teb...@gmail.com wrote: [Roland] yes, there is: subclass+extend the JSON-encoder, see pydoc json. Please read the original post before answering. What you suggested does not work since NaN is of float type. You may be able to override a bit

Re: Encoding NaN in JSON

2013-04-17 Thread Chris Angelico
On Thu, Apr 18, 2013 at 11:39 AM, Roland Koebler r.koeb...@yahoo.de wrote: as a quickhack, you could even monkey patch json.encoder.floatstr with a wrapper which returns N/A for NaN. (I've tested it: It works.) Wait... you can do that? It's internal to iterencode, at least in Python 3.3

Encoding NaN in JSON

2013-04-16 Thread Miki Tebeka
Greetings, I'm trying to find a way to have json emit float('NaN') as 'N/A'. I can't seem to find a way since NaN is a float, which means overriding default won't help. Any simple way to do this? Thanks, -- Miki -- http://mail.python.org/mailman/listinfo/python-list

Re: Encoding NaN in JSON

2013-04-16 Thread Tim Roberts
Miki Tebeka miki.teb...@gmail.com wrote: I'm trying to find a way to have json emit float('NaN') as 'N/A'. I can't seem to find a way since NaN is a float, which means overriding default won't help. Any simple way to do this? No. There is no way to represent NaN in JSON. It's simply not part

[issue11949] Make float('nan') unorderable

2013-02-18 Thread Marc Schlaich
Marc Schlaich added the comment: I'm +1 for a warning. The current behavior is really unexpectable: In [6]: sorted([nan, 0, 1, -1]) Out[6]: [nan, -1, 0, 1] In [7]: sorted([0, 1, -1, nan]) Out[7]: [-1, 0, 1, nan] In [8]: sorted([0, nan, 1, -1]) Out[8]: [0, nan, -1, 1] -- nosy

[issue11949] Make float('nan') unorderable

2013-02-18 Thread Raymond Hettinger
warnings are a bit of PITA to shut-off. For something like NaN ordering, a warning is likely to inflict more harm on the users than the NaN ordering issue itself. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11949

Re: a.index(float('nan')) fails

2012-10-28 Thread Ethan Furman
Steven D'Aprano wrote: The list.index method tests for the item with equality. Since NANs are mandated to compare unequal to anything, including themselves, index cannot match them. This is incorrect. .index() uses identity first, then equality, and will match the same NaN in a list

Re: a.index(float('nan')) fails

2012-10-27 Thread Thomas Rachel
Am 27.10.2012 06:48 schrieb Dennis Lee Bieber: I don't know about the more modern calculators, but at least up through my HP-41CX, HP calculators didn't do (binary) floating point... They did a form of BCD with a fixed number of significant /decimal/ digits Then, what about sqrt(x)**2

Re: a.index(float('nan')) fails

2012-10-27 Thread Nobody
On Thu, 25 Oct 2012 22:04:52 -0400, Terry Reedy wrote: Containment of nan in collection is tested by is, not ==. AFAICT, it isn't specific to NaN. The test used by .index() and in appears to be equivalent to: def equal(a, b): return a is b or a == b IOW, it always checks

Re: a.index(float('nan')) fails

2012-10-27 Thread Nobody
On Sat, 27 Oct 2012 08:56:16 +0200, Thomas Rachel wrote: Am 27.10.2012 06:48 schrieb Dennis Lee Bieber: I don't know about the more modern calculators, but at least up through my HP-41CX, HP calculators didn't do (binary) floating point... They did a form of BCD with a fixed number of

Re: a.index(float('nan')) fails

2012-10-27 Thread Mark Adam
On Thu, Oct 25, 2012 at 9:04 PM, Terry Reedy tjre...@udel.edu wrote: On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote: a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) Traceback (most recent call last): File stdin

Re: a.index(float('nan')) fails

2012-10-26 Thread Cameron Simpson
On 25Oct2012 22:04, Terry Reedy tjre...@udel.edu wrote: | Containment of nan in collection is tested by is, not ==. | nan = float('nan') | nan2 = float('nan') | nan2 is nan | False This argues otherwise, and for use of math.isnan() instead. I expect you were making the point that another

Re: a.index(float('nan')) fails

2012-10-26 Thread Terry Reedy
On 10/25/2012 10:44 PM, Steven D'Aprano wrote: On Thu, 25 Oct 2012 22:04:52 -0400, Terry Reedy wrote: It is a consequence of the following, which some people (but not all) believe is mandated by the IEEE standard. nan = float('nan') nan is nan True The IEEE 754 standard says nothing

Re: a.index(float('nan')) fails

2012-10-26 Thread Terry Reedy
On 10/25/2012 10:19 PM, MRAB wrote: On 2012-10-26 03:04, Terry Reedy wrote: On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote: a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) This is a second nan object

Re: a.index(float('nan')) fails

2012-10-26 Thread Steven D'Aprano
On Fri, 26 Oct 2012 03:54:02 -0400, Terry Reedy wrote: On 10/25/2012 10:44 PM, Steven D'Aprano wrote: On Thu, 25 Oct 2012 22:04:52 -0400, Terry Reedy wrote: It is a consequence of the following, which some people (but not all) believe is mandated by the IEEE standard. nan = float('nan

Re: a.index(float('nan')) fails

2012-10-26 Thread Steven D'Aprano
On Fri, 26 Oct 2012 04:00:03 -0400, Terry Reedy wrote: On 10/25/2012 10:19 PM, MRAB wrote: In summary, .index() looks for an item which is equal to its argument, but it's a feature of NaN (as defined by the standard) that it doesn't equal NaN, therefore .index() will never find it. Except

Re: a.index(float('nan')) fails

2012-10-26 Thread MRAB
On 2012-10-26 17:23, Steven D'Aprano wrote: On Fri, 26 Oct 2012 04:00:03 -0400, Terry Reedy wrote: On 10/25/2012 10:19 PM, MRAB wrote: In summary, .index() looks for an item which is equal to its argument, but it's a feature of NaN (as defined by the standard) that it doesn't equal NaN

Re: a.index(float('nan')) fails

2012-10-26 Thread Chris Angelico
On Sat, Oct 27, 2012 at 3:23 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In real life, you are *much* more likely to run into these examples of insanity of floats than to be troubled by NANs: - associativity of addition is lost - distributivity of multiplication is lost -

Re: a.index(float('nan')) fails

2012-10-26 Thread Steven D'Aprano
On Sat, 27 Oct 2012 03:45:46 +1100, Chris Angelico wrote: On Sat, Oct 27, 2012 at 3:23 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: In real life, you are *much* more likely to run into these examples of insanity of floats than to be troubled by NANs: - associativity of

Re: a.index(float('nan')) fails

2012-10-26 Thread Terry Reedy
is mandated by the IEEE standard. nan = float('nan') nan is nan True The IEEE 754 standard says nothing about object identity. It only discusses value equality. nan == nan False IEEE 754 states that all NANs compare unequal to everything, including NANs with the same bit value. It doesn't

Re: a.index(float('nan')) fails

2012-10-26 Thread Terry Reedy
On 10/26/2012 12:23 PM, Steven D'Aprano wrote: On Fri, 26 Oct 2012 04:00:03 -0400, Terry Reedy wrote: This inconsistency is an intentional decision to not propagate the insanity of nan != nan to Python collections. That's a value judgement about NANs which is not shared by everyone. Quite

Re: a.index(float('nan')) fails

2012-10-26 Thread Devin Jeanpierre
On Fri, Oct 26, 2012 at 2:40 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The problem isn't with the associativity, it's with the equality comparison. Replace x == y with abs(x-y)epsilon for some epsilon and all your statements fulfill people's expectations. O RYLY? Would

a.index(float('nan')) fails

2012-10-25 Thread mamboknave
a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) Traceback (most recent call last): File stdin, line 1, in module ValueError: list.index(x): x not in list That means, the function .index() cannot detect nan values

Re: a.index(float('nan')) fails

2012-10-25 Thread Terry Reedy
On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote: a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) Traceback (most recent call last): File stdin, line 1, in module ValueError: list.index(x): x not in list That means

Re: a.index(float('nan')) fails

2012-10-25 Thread Cameron Simpson
On 25Oct2012 18:46, mambokn...@gmail.com mambokn...@gmail.com wrote: | a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | a | [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | a.index(float('nan')) | Traceback (most recent call last): | File stdin, line 1, in module | ValueError: list.index(x): x

Re: a.index(float('nan')) fails

2012-10-25 Thread MRAB
On 2012-10-26 03:04, Terry Reedy wrote: On 10/25/2012 9:46 PM, mambokn...@gmail.com wrote: a = [float('nan'), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a [nan, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] a.index(float('nan')) Traceback (most recent call last): File stdin, line 1, in module ValueError

Re: a.index(float('nan')) fails

2012-10-25 Thread mamboknave
On Thursday, October 25, 2012 7:16:02 PM UTC-7, Cameron Simpson wrote: Of course!! How could I get into that trap?? Thanks to you to Terry -- http://mail.python.org/mailman/listinfo/python-list

Re: a.index(float('nan')) fails

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 18:46:20 -0700, mamboknave wrote: That means, the function .index() cannot detect nan values. It happens on both Python 2.6 and Python 3.1 Is this a bug? Or I am not using .index() correctly? You shouldn't be using index() or == to detect NANs. The right way to detect

Re: a.index(float('nan')) fails

2012-10-25 Thread Steven D'Aprano
On Thu, 25 Oct 2012 22:04:52 -0400, Terry Reedy wrote: It is a consequence of the following, which some people (but not all) believe is mandated by the IEEE standard. nan = float('nan') nan is nan True The IEEE 754 standard says nothing about object identity. It only discusses value

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-08-24 Thread Roundup Robot
Roundup Robot added the comment: New changeset 31a7ff299698 by Mark Dickinson in branch '2.7': Remove overeager test (don't depend on the sign of a nan; cf. issue #14521) http://hg.python.org/cpython/rev/31a7ff299698 -- ___ Python tracker rep

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-08-24 Thread Roundup Robot
Roundup Robot added the comment: New changeset 121cb9596e7d by Mark Dickinson in branch '3.2': Remove overeager test (don't depend on the sign of a nan; cf. issue #14521) http://hg.python.org/cpython/rev/121cb9596e7d -- ___ Python tracker rep

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-29 Thread Roundup Robot
Roundup Robot devn...@psf.upfronthosting.co.za added the comment: New changeset c468511fc887 by Mark Dickinson in branch 'default': Issue #14521: Make result of float('nan') and float('-nan') more consistent across platforms. Further, don't rely on Py_HUGE_VAL for float('inf'). http

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-29 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Now fixed. -- resolution: - fixed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14521 ___

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-29 Thread Mark Dickinson
Changes by Mark Dickinson dicki...@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14521 ___ ___

[issue1762561] unable to serialize Infinity or NaN on ARM using marshal

2012-04-22 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: [Dirkjan] Could we reconsider ARM support at this time? Note that it's just the Linux old ABI (OABI) that needs this patch; ARM / Linux using the new family of ABIs (EABI) should be fine. IIUC, this old ABI is being phased out, but I

[issue1762561] unable to serialize Infinity or NaN on ARM using marshal

2012-04-22 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: This issue remains as won't fix. ARM is supported; just OABI is not, and never will be. If anybody needs that, they will have to maintain their own fork of Python. -- ___ Python tracker

[issue14613] time.time can return NaN

2012-04-20 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: See http://patch-tracker.debian.org/package/python2.7 for the list of patches applied to Python 2.7 in Debian. I don’t know if there are more patches in Ubuntu. -- nosy: +eric.araujo ___ Python

[issue14613] time.time can return NaN

2012-04-19 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@gmail.com: -- title: time.time can return None or NaN - time.time can return NaN ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14613

[issue14613] time.time can return NaN

2012-04-19 Thread STINNER Victor
STINNER Victor victor.stin...@gmail.com added the comment: So NaN is a possible result from time.time()? Oops. I don't know if it is possible. I just know that it cannot return None :-) _PyTime_gettimeofday() fills a structure having two integer fields (tv_sec, tv_usec), and floattime() uses

[issue14613] time.time can return None or NaN

2012-04-18 Thread Michael Foord
New submission from Michael Foord mich...@voidspace.org.uk: time.time() can return None, or sometimes NaN. If it can't get a proper value from the OS then I would expect it to throw an exception. The docs don't mention anything about error conditions. This was originally reported to Ubuntu

[issue14613] time.time can return None or NaN

2012-04-18 Thread Michael Foord
Changes by Michael Foord mich...@voidspace.org.uk: -- stage: - test needed type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14613 ___

[issue14613] time.time can return None or NaN

2012-04-18 Thread Michael Foord
Changes by Michael Foord mich...@voidspace.org.uk: -- versions: +Python 2.7, Python 3.2, Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14613 ___

[issue14613] time.time can return None or NaN

2012-04-18 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Issue 14028 is related. -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14613 ___

[issue14613] time.time can return None or NaN

2012-04-18 Thread Roman
Changes by Roman roman.yepis...@canonical.com: -- nosy: +rye ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14613 ___ ___ Python-bugs-list mailing

[issue14613] time.time can return None or NaN

2012-04-18 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: What exact version of Python was used? What's the complete list of patches that was applied to this Python version? As discussed in #14028, this behavior doesn't correspond to the code at all. So hardware error, compiler error, and

[issue14613] time.time can return None or NaN

2012-04-18 Thread STINNER Victor
STINNER Victor victor.stin...@gmail.com added the comment: time.time() can return None, or sometimes NaN It is possible that it returns NaN, but it cannot return None. time.time() implementation of Python 2.7: static PyObject * time_time(PyObject *self, PyObject *unused) { double secs

[issue14613] time.time can return None or NaN

2012-04-18 Thread Michael Foord
Michael Foord mich...@voidspace.org.uk added the comment: So NaN is a possible result from time.time()? Perhaps that should be mentioned in the docs. Is returning NaN preferable to failing with an exception? -- ___ Python tracker rep

[issue14613] time.time can return None or NaN

2012-04-18 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: It is possible that it returns NaN How is that possible? I can't see any way that the Python 2.7 implementation of floattime could return a NaN. In each case, floattime appears to be extracting integer fields from some suitable struct

[issue1762561] unable to serialize Infinity or NaN on ARM using marshal

2012-04-13 Thread Dirkjan Ochtman
Dirkjan Ochtman dirk...@ochtman.nl added the comment: Could we reconsider ARM support at this time? Seems like ARM support has been surging over the past few years, and it's becoming more supported by Linux distributions. Seems like a pity to leave a patch like this out here. -- nosy:

[issue1762561] unable to serialize Infinity or NaN on ARM using marshal

2012-04-13 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1762561 ___

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-10 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: The pickle issue occurs in the numpy module, on windows I'm still not clear what the issue is. Is there something wrong in the output of the pickle example you show? -- ___ Python tracker

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-10 Thread mattip
mattip matti.pi...@gmail.com added the comment: The pickle output has the sign-bit set. Ignoring the sign-bit, it is unpickled correctly. However math.copysign using this value will now return minus on platforms where copysign(3., float('nan')) is known to work. Perhaps the whole can of worms

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-10 Thread Mark Dickinson
, I don't see this as a bug: pickle is transferring the sign bit correctly, so the only issue again is that float('nan') happens to produce a nan whose sign bit is set (depending on platform, compiler options, etc.). I don't see it as a problem that one can end up with some 'positive' nans

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Thanks for the updated patch! (BTW, you can attach patches as files to the issue rather than writing them inline.) Yes, this patch is more along the lines that I was thinking of. There are some issues, though: (1) we need to deal with

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Here's an example based on the dtoa.c code. It only changes the return value of float('nan'), and doesn't affect any other existing uses of the Py_NAN macro. It needs tests. -- keywords: +patch Added file: http://bugs.python.org

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: May be it would be more reasonable if math.copysign(1., float('nan')) return a float('nan')? -- nosy: +storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14521

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: May be it would be more reasonable if math.copysign(1., float('nan')) return a float('nan')? -1. That would go against all the existing standards. -- ___ Python tracker rep...@bugs.python.org

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread mattip
mattip matti.pi...@gmail.com added the comment: Your patch is much more reasonable than mine. Should I add a test that fails pre-patch and passes with the patch, or one that is skipped pre-patch and passes post-patch? I'm not sure what is accepted in the cpython development cycle --

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: The test should fail pre-patch and pass post-patch. There will be no state in the repository where the patch is present and fails, since it will be committed along with the patch. Skipping tests is only ok for tests that lack

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: Also, mattip: if you want to contribute some chunk of code (such as the test), please submit a contributor form. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14521

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread mattip
mattip matti.pi...@gmail.com added the comment: I added tests to the mark.dickinson patch, test.test_math passes. -- Added file: http://bugs.python.org/file25165/math_patch2.txt ___ Python tracker rep...@bugs.python.org

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread mattip
mattip matti.pi...@gmail.com added the comment: I also submitted a form. Sorry about the patch name, still learning. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14521 ___

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-09 Thread mattip
mattip matti.pi...@gmail.com added the comment: The pickle issue occurs in the numpy module, on windows cPickle.dumps(numpy.array(float('nan'))) yeilds cnumpy.core.multiarray\n_reconstruct\np1\n(cnumpy\nndarray\np2\n(I0\ntS'b'\ntRp3\n(I1\n(tcnumpy\ndtype\np4\n(S'f8'\nI0\nI1\ntRp5\n(I3\nS

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-08 Thread mattip
mattip matti.pi...@gmail.com added the comment: I was going to add a test for this to Lib/test/test_math.py, but found this comment: # copysign(INF, NAN) may be INF or it may be NINF, since # we don't know whether the sign bit of NAN is set on any # given platform. I

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-08 Thread Antoine Pitrou
Changes by Antoine Pitrou pit...@free.fr: -- components: +Interpreter Core -None nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14521 ___

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-08 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Hmm. I don't see this as a bug: the sign of a nan isn't really all that meaningful anyway, and this doesn't (AFAIK) contradict any documentation. On the other hand, given that most other aspects of floating-point are now reasonably

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-08 Thread mattip
of Py_NAN to a unsigned char[]. It passes the tests in test.test_math and handles the copysign in a more intuitive way math.copysign(1., float('nan')) = 1. on win32, microsoft compiler diff -r efeca6ff2751 Include/pymath.h --- a/Include/pymath.h Thu Apr 05 22:51:00 2012 +0200 +++ b/Include

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-07 Thread mattip
math.copysign(1., float('nan')) -1.0 math.copysign(1., float('-nan')) 1.0 -- components: None messages: 157746 nosy: mattip priority: normal severity: normal status: open title: math.copysign(1., float('nan')) returns -1. type: behavior versions: Python 2.7

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-07 Thread Martin v . Löwis
Martin v. Löwis mar...@v.loewis.de added the comment: This is a near duplicate of issue7281. Most likely, copysign is behaving correctly, and it's already the float conversion that errs. For struct.pack('d', float('nan')), I get '\x00\x00\x00\x00\x00\x00\xf8\xff'; for -nan, I get '\x00\x00

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-07 Thread mattip
mattip matti.pi...@gmail.com added the comment: It appears that microsoft decided NAN will be represented by '\x00\x00\x00\x00\x00\x00\xf8\xff', which has the sign bit set. Compiling this c code with visual 9.0 gives the correct answers for the first value, and a mess for the second

[issue14521] math.copysign(1., float('nan')) returns -1.

2012-04-07 Thread mattip
mattip matti.pi...@gmail.com added the comment: Sorry for the garbage c code, the comment however is correct: Py_NAN is created with the sign bit set (on windows), and then _copysign on windows uses the sign bit to determine the output, which results in the wrong answer. --

[issue1762561] unable to serialize Infinity or NaN on ARM using marshal

2012-03-13 Thread Nir Soffer
Nir Soffer nir...@gmail.com added the comment: As someone who has to develop on ARM OABI, I find this won't fix policy rather frustrating. If you happen to need this patch on 2.7, this is the same patch as arm-float2.diff, which can be applied cleanly to release 2.7.2. Changes from

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Gregory P. Smith
Changes by Gregory P. Smith g...@krypto.org: -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14028 ___ ___ Python-bugs-list

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Martin v . Löwis
Changes by Martin v. Löwis mar...@v.loewis.de: -- versions: -Python 2.6, Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14028 ___ ___

[issue13986] ValueError: cannot convert float NaN to integer

2012-02-16 Thread Gregory P. Smith
Gregory P. Smith g...@krypto.org added the comment: FYI - A similar NaN appearing in an unexpected place (the random module in this case) bug that I just filed - http://bugs.python.org/issue14028. I don't actually know if these will be related or not. -- nosy: +gregory.p.smith

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Mark Dickinson
Changes by Mark Dickinson dicki...@gmail.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14028 ___ ___

[issue13986] ValueError: cannot convert float NaN to integer

2012-02-16 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: My guess would be not related. My best guess for this issue is that it's caused by some mismatch in the struct stat declarations / uses on MIPS / Linux. A Google search for MIPS and stat suggests that there are problems in this area.

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Raymond Hettinger
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- assignee: - rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14028 ___ ___

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Mark Dickinson
that the error is really coming from the int() call in the traceback. But now that implies that the random call is returning NaN, which looks unpossible from the code (random_random in Modules/_randommodule.c). static PyObject * random_random(RandomObject *self) { unsigned long

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: The bugs.launchpad.net URL shows a call to 'entropy.choice'. Any idea what 'entropy' is? Could it be that they're using their own Random subclass, not tied to the Python MT implementation? --

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: The hypothesis that time.time() is returning NaN doesn't match the provided traceback. If time.time() had returned NaN, the exception would have happened earlier, on line 113 in random.py: long(time.time() * 256) I'm wondering

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: I'm wondering if the NaN arises in the C code for random(): I don't think that's possible. In the second line: return PyFloat_FromDouble((a*67108864.0+b)*(1.0/9007199254740992.0)); a and b are already C unsigned longs, so no matter

[issue14028] random.choice hits ValueError: cannot convert float NaN to integer

2012-02-16 Thread Gregory P. Smith
Gregory P. Smith g...@krypto.org added the comment: I think my claim the hardware appears healthy was premature. I misunderstood our initial error report internally on where the code ran and was looking at the wrong host. doh. my bad. Several more of these have been found in the last week

<    2   3   4   5   6   7   8   9   10   11   >