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. The OP

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

2012-10-27 Thread Mark Adam
On Thu, Oct 25, 2012 at 9:04 PM, 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):

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 n

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 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)**

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

2012-10-26 Thread Devin Jeanpierre
On Fri, Oct 26, 2012 at 2:40 PM, Steven D'Aprano wrote: >> The problem isn't with the associativity, it's with the equality >> comparison. Replace "x == y" with "abs(x-y)> and all your statements fulfill people's expectations. > > O RYLY? > > Would you care to tell us which epsilon they should use

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 f

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

2012-10-26 Thread Terry Reedy
On 10/26/2012 11:26 AM, Steven D'Aprano wrote: 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 mandate

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 > 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 >> - distr

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

2012-10-26 Thread Chris Angelico
On Sat, Oct 27, 2012 at 3:23 AM, Steven D'Aprano 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 > - commutativity of addition is

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, ther

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. >

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. >>> >>> >>>

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, and it is not in t

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 noth

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

2012-10-25 Thread Cameron Simpson
On 25Oct2012 22:04, Terry Reedy 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 NaN is di

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 discu

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 detec

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 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 "", line 1, in ValueError: list.index(x):

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

2012-10-25 Thread Cameron Simpson
On 25Oct2012 18:46, 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 "", line 1, in | ValueError: list.index(x): x not in list | | Tha

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 "", line 1, in ValueError: list.index(x): x not in list That means, the function

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 "", line 1, in ValueError: list.index(x): x not in list That means, the function .index() cannot detect nan values. It happens