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

Guido van Rossum guido at python.org
Tue Jan 27 23:35:50 CET 2015

I'm still confused. We're talking about a function that compares two simple
values, right? Where does the sequence of values come from? Numpy users do
everything by the array, but they already have an isclose(). Or perhaps
you're talking about assertApproxEqual in test_statistics.py? That has so
many ways to specify the relative and absolute tolerance that I give up
understanding it. The docstring doesn't give any clarity -- it simply
describes the behaviors, it doesn't say when you should be using both.
"[...] a naive implementation of relative error testing can run into
trouble around zero" (followed by a single example) doesn't really help me.

On Tue, Jan 27, 2015 at 2:14 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> On Tue, Jan 27, 2015 at 2:00 PM, Guido van Rossum <guido at python.org>
> wrote:
>> I really appreciate this API design approach, and in this case I started
>>> out with that idea. But I think this is likely to be used where you need to
>>> test a bunch of values with single function/set of parameters. In
>>> TestCase.assertIsCloseTo, as well as home grown loops and comprehensions.
>> I assume you mean assertNotAlmostEqual
>> <https://hg.python.org/cpython/file/94d8524086bd/Lib/unittest/case.py#l525>.
> Sorry -- I meant a Hypothetical assertIsCLoseTo -- which would wrap the
> proposed is_close_to(), but apply it to a entire sequence, like
> assertNotAlmostEqual
> <https://hg.python.org/cpython/file/94d8524086bd/Lib/unittest/case.py#l525>.
> does.
>> This is actually the same misguided two-for-one design. You *must*
>> specify exactly one of delta or places, and the code takes a different
>> path. Also, it looks like both are actually absolute tolerance.
> Yes, both are an absolute tolerance -- which , I think makes it a slightly
> less misguided design -- you aren't selecting two different
> functionalities, just two ways to spell the tolerance.
> So what argument are you making here?
> The point was that if the user applies one set of parameters to a sequence
> of values that may have some zeros in it, -- we need it in one function.
> Nathaniel has found that to be a fairly common use-case for the numpy
> allclose()
> -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

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150127/db7c7c5e/attachment.html>

More information about the Python-ideas mailing list