Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74644
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.068 |
| X-Spam-Evidence | '*H*': 0.86; '*S*': 0.00; '"who': 0.09; 'logic': 0.09; 'cc:addr:python-list': 0.11; '(b,': 0.16; '(something': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'nan': 0.16; 'singleton': 0.16; 'spotted': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'work,': 0.20; '(the': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'instance,': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'handling': 0.26; 'header:In-Reply-To:1': 0.27; 'record': 0.27; 'leave': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'allows': 0.31; 'lists': 0.32; 'probably': 0.32; 'another': 0.32; 'checking': 0.33; 'entirely': 0.33; 'fri,': 0.33; 'maybe': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; "he's": 0.36; 'useful': 0.36; 'possible': 0.36; 'should': 0.36; 'checks': 0.38; 'list,': 0.38; 'planning': 0.38; 'either': 0.39; 'how': 0.40; 'easy': 0.60; 'information': 0.63; 'more': 0.64; 'accounts': 0.64; 'different': 0.65; 'here': 0.66; 'useful.': 0.68; 'business': 0.70; 'jul': 0.74; 'special': 0.74; 'subject:For': 0.78; '"not': 0.84; 'bow': 0.84; 'to:none': 0.92; 'loan': 0.93 |
| 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:cc :content-type; bh=Z0L/ohnpPQ6QBP2LbQvA/nNXtJSz5Zl/v0K+hoOIX4o=; b=R/4ZtuItUu0jR2h6ic51hIozdsnSfQ4wpTl6/GP+TK8Sm/Yj1soC+YuiaU8D0L7vxU tMDz5724dP/MvMLLTZswjU2N3CtWzRw151P+QtvXdUJw82yFKzwNcIQq7Nufk2hpAYsD SLBf4hMdMu6yEo1+AwyWi2iw7mc7lVrmxoXk6zNUijGHweeLXgjv0nN/Ft3YLz5nBBxq JQIduD7zGkrDKZwnKm+Q6IAJaP63PtpPqDqiIFs1VKgzWgKVm9+5Ea5GTGvshCAnrHYs VoS0iiw8r2ASe+pTeVVXVW+1v6Ch0C5zlQ+NQKnc/7vyhJlfb9zplL0jonpZ+OeiU7l3 5NFQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.178.66 with SMTP id cw2mr5186353vdc.93.1405611384721; Thu, 17 Jul 2014 08:36:24 -0700 (PDT) |
| In-Reply-To | <osx38e010kj.fsf@gmail.com> |
| References | <53BC05FB.4050707@jmunch.dk> <53BD70F4.4000504@stoneleaf.us> <53BDAF90.8010709@jmunch.dk> <CAPM-O+yiioLm-UiV2fYqc2n9qZrN+_v6RkeqJ7mOQ3Kq+cH0CQ@mail.gmail.com> <mailman.11716.1404946997.18130.python-list@python.org> <osx38e010kj.fsf@gmail.com> |
| Date | Fri, 18 Jul 2014 01:36:24 +1000 |
| Subject | Re: NaN comparisons - Call For Anecdotes |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11929.1405611387.18130.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1405611387 news.xs4all.nl 2857 [2001:888:2000:d::a6]:60220 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74644 |
Show key headers only | View raw
On Fri, Jul 18, 2014 at 1:12 AM, Johann Hibschman <jhibschman@gmail.com> wrote:
> Well, I just spotted this thread. An easy example is, well, pretty much
> any case where SQL NULL would be useful. Say I have lists of borrowers,
> the amount owed, and the amount they paid so far.
>
> nan = float("nan")
> borrowers = ["Alice", "Bob", "Clem", "Dan"]
> amount_owed = [100.0, nan, 200.0, 300.0]
> amount_paid = [100.0, nan, nan, 200.0]
> who_paid_off = [b for (b, ao, ap) in
> zip(borrowers, amount_owed, amount_paid)
> if ao == ap]
>
> I want to just get Alice from that list, not Bob. I don't know how much
> Bow owes or how much he's paid, so I certainly don't know that he's paid
> off his loan.
>
But you also don't know that he hasn't. NaN doesn't mean "unknown", it
means "Not a Number". You need a more sophisticated system that allows
for uncertainty in your data. I would advise using either None or a
dedicated singleton (something like `unknown = object()` would work,
or you could make a custom type with a more useful repr), and probably
checking for it explicitly. It's entirely possible that you do
virtually identical (or virtually converse) checks but with different
handling of unknowns - for instance, you might have one check for "who
should be sent a loan reminder letter" in which you leave out all
unknowns, and another check for "which accounts should be flagged for
human checking" in which you keep the unknowns (and maybe ignore every
loan <100.0). You have a special business case here (the need to
record information with a "maybe" state), and you need to cope with
it, which means dedicated logic and planning and design and code.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: NaN comparisons - Call For Anecdotes "Anders J. Munch" <2014@jmunch.dk> - 2014-07-10 01:03 +0200
Re: NaN comparisons - Call For Anecdotes Johann Hibschman <jhibschman@gmail.com> - 2014-07-17 11:12 -0400
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-18 01:36 +1000
Re: NaN comparisons - Call For Anecdotes Johann Hibschman <jhibschman@gmail.com> - 2014-07-17 14:49 -0400
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-18 04:55 +1000
Re: NaN comparisons - Call For Anecdotes Marko Rauhamaa <marko@pacujo.net> - 2014-07-17 22:10 +0300
Re: NaN comparisons - Call For Anecdotes Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-17 14:39 -0600
Re: NaN comparisons - Call For Anecdotes Marko Rauhamaa <marko@pacujo.net> - 2014-07-18 00:08 +0300
Re: NaN comparisons - Call For Anecdotes Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-17 17:00 -0600
Re: NaN comparisons - Call For Anecdotes Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-17 17:07 -0600
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-18 04:59 +1000
Re: NaN comparisons - Call For Anecdotes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-18 17:57 +0000
Re: NaN comparisons - Call For Anecdotes Chris Angelico <rosuav@gmail.com> - 2014-07-19 05:49 +1000
csiph-web