Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'convention.': 0.07; 'python': 0.08; 'from:addr:python': 0.09; 'python-dev,': 0.09; '>>>': 0.12; 'wrote:': 0.14; 'dictionaries': 0.16; 'equality': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'nan': 0.16; 'presumably,': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; 'rohdewald': 0.16; 'subject:key': 0.16; 'subject:set': 0.16; 'wolfgang': 0.16; 'header:In-Reply-To:1': 0.21; 'assume': 0.23; 'objects,': 0.23; 'objects': 0.23; 'received:84': 0.25; '(and': 0.25; 'specified': 0.26; "i'm": 0.27; '(not': 0.28; 'checking': 0.29; 'discussed': 0.29; 'themselves.': 0.29; 'second': 0.30; 'equal': 0.31; 'to:addr:python-list': 0.33; 'things': 0.33; 'thinking': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'identical': 0.35; 'implies': 0.35; 'reply-to:addr:python.org': 0.35; 'thread': 0.37; 'reasons': 0.37; 'think': 0.38; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'itself.': 0.39; 'sets': 0.39; 'to:addr:python.org': 0.39; 'making': 0.67; 'header:Reply- To:1': 0.72; 'reply-to:no real name:2**0': 0.72; 'delaney': 0.84; 'edwards': 0.91; 'mystery': 0.96 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmwGAAuF4k1UXebj/2dsb2JhbABHDpgujg93xWiDF4MHBJUNil0 Date: Sun, 29 May 2011 18:44:08 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: python-list@python.org Subject: Re: float("nan") in set or as key References: <4DE1881C.8000701@mrabarnett.plus.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 28 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306691054 news.xs4all.nl 49178 [::ffff:82.94.164.166]:37242 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6553 On 29/05/2011 15:41, Grant Edwards wrote: > On 2011-05-29, Wolfgang Rohdewald wrote: >> On Sonntag 29 Mai 2011, Tim Delaney wrote: >>> There's a second part the mystery - sets and dictionaries (and >>> I think lists) assume that identify implies equality (hence >>> the second result). This was recently discussed on >>> python-dev, and the decision was to leave things as-is. >> >> On Sonntag 29 Mai 2011, Grant Edwards wrote: >>> Even if they are the same nan, it's still not equal to itself. >> >> if I understand this thread correctly, they are not equal to itself >> as specified by IEEE > > And Python follows that convention. > >> but Python treats them equal in sets and dictionaries for performance >> reasons > > It treats them as identical (not sure if that's the right word). The > implementation is checking for ( A is B or A == B ). Presumably, the > assumpting being that all objects are equal to themselves. That > assumption is not true for NaN objects, so the buggy behavior is > observed. > Would there be any advantage to making NaN a singleton? I'm thinking that it could make checking for it cheaper in the implementation of sets and dicts. Or making NaN unhashable?