[Python-ideas] PEP 485: A Function for testing approximate equality

Chris Barker chris.barker at noaa.gov
Sat Jan 24 21:46:30 CET 2015


On Sat, Jan 24, 2015 at 12:21 PM, Guido van Rossum <guido at python.org> wrote:

> On Sat, Jan 24, 2015 at 11:59 AM, Chris Barker <chris.barker at noaa.gov>
> wrote:
>
>>
>> I'd much rather require people to have to think about what makes sense
>> for their use case than get trapped by a default that's totally
>> inappropriate.
>>
>
> And by the time you have thought through your use case you're probably
> better off just writing abs(x-y) <= eps for some eps that you decide from
> your use case.
>

Exactly why I never thought a function to simply do an absolute closeness
test wasn't worth it.

This is for the case where you want a relative test, but also want
something sane for a comparison to zero. If there aren't any zeros in your
data, you don't need to think about it. If there are, it will fail, and
then you will have to think about it.

The number of messages written to debate this one simple formula make me
> think it's not so simple after all.
>

well, we shouldn't underestimate the capacity for bike-shedding.

Next I plan to go through full set of messages since I posted the PEP, and
tease out the real disagreements/decision points -- I guess I'll see how
that pans out.


> So perhaps this is, once again, something that's better off as a recipe?
>

I hope not, but if consensus can't be reached, perhaps so.


> Alternatively, maybe a useful approach to resolving this debate could be
> to look for places in actual code where people have solved this for their
> own use case (as in, written by someone else to solve a real problem, not
> made up as an example).
>

I've got a pile of uses of numpy's all_close (mostly tests) and it would be
easy to search for those in other places. Not sure how to find other uses
in other people's code though.

And, of course, Steven put something similar in the statistics tests.

So maybe the idea that this is primarily a new testing utility is the way
to go.


>
> Then if you see a particular pattern occur repeatedly, you might be able
> to use that evidence to suggest the right helper function that does the
> whole thing in one call, and by looking at variations you might get a good
> insight in the needed parameters and defaults.
>

I have no idea how to find those, but if anyone has suggestions for how to
look, or examples in their own code, that would be great.

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150124/f6109326/attachment.html>


More information about the Python-ideas mailing list