Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'model,': 0.05; 'means,': 0.07; 'valueerror:': 0.07; 'python': 0.09; 'noted,': 0.09; 'such.': 0.09; 'terry': 0.09; 'cc:addr:python-list': 0.10; '(but': 0.15; 'conforms': 0.16; 'nan': 0.16; 'oct': 0.16; 'record,': 0.16; 'reedy': 0.16; 'subject:fails': 0.16; 'which,': 0.16; 'wrote:': 0.17; 'detect': 0.17; 'thu,': 0.17; 'memory': 0.18; 'appropriate': 0.20; '"",': 0.22; 'bug?': 0.22; 'runs': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'skip:[ 10': 0.26; '(most': 0.27; '2.6': 0.27; 'message-id:@mail.gmail.com': 0.27; '3.1': 0.29; '>>>>': 0.29; 'consequence': 0.29; 'function': 0.30; 'file': 0.32; 'addresses': 0.32; 'could': 0.32; 'traceback': 0.33; 'values.': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'list': 0.35; 'false': 0.35; 'returning': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'should': 0.36; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'nothing': 0.38; 'header:Received:5': 0.40; 'skip:n 10': 0.63; 'email addr:gmail.com': 0.63; 'here': 0.65; 'potentially': 0.66; 'believe': 0.69; 'correctly?': 0.84; 'phenomenon': 0.84; 'whatsoever.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=S8mmVju2xe9ejq3evSmfHrVE7MFmhveU134VW+jWZ3c=; b=ewW9t4tGU5vGmNPFQe6lg+VsV7IT67abF9XOsCAxBXp++B2nIa+dTbBcHuQ9WXimcS CI7pG+lasKCj4UkOA/osOaVGURqHsagXKpoakrJXX9WrHtgV/kb2dx9q1QknlMhHe/4H x6yPLqkwYry3zddvojIqygfpGE4qAJKv9E4jGQ+M2adtzQXyy9EOn6qQ/BE5rEMa6d4o R/5YHCGqb+jwKVdj2y/iIcwU/Eabrm1fWJRFEHDsqH8BtFVC7uUcVodVyhAvqQypAqmQ yg+s6TO0BJt/WylClJ9IVQVOK1zm5pmPzpuzvUAeNhErNzXkgKMpKYgBzFvb8oJiOD3n 0+5g== MIME-Version: 1.0 In-Reply-To: References: Date: Sat, 27 Oct 2012 13:33:51 -0500 Subject: Re: a.index(float('nan')) fails From: Mark Adam To: Terry Reedy Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351362840 news.xs4all.nl 6948 [2001:888:2000:d::a6]:50258 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32288 On Thu, Oct 25, 2012 at 9:04 PM, Terry Reedy wrote: > On 10/25/2012 9:46 PM, mamboknave@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 .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? > > > 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 It should be noted, for the record, that "nan is nan" returning True has nothing to do with the concept of numbers or the IEEE standard and is purely a consequence that Python runs on hardware with memory addresses and such. >>>> nan == nan > False Here, equality, IS about number and this is appropriate and conforms to the IEEE standard. >>>> nanlist = [nan] >>>> nan in nanlist > True >>>> nanlist.index(nan) > 0 Here you just see an phenomenon with the python object/reference model, which, being as it is, has nothing to do with numbers. This is an area which, potentially could be changed in Python without violating the IEEE standard whatsoever. Mark