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

Chris Barker chris.barker at noaa.gov
Wed Jan 28 00:00:27 CET 2015

On Tue, Jan 27, 2015 at 2:35 PM, Guido van Rossum <guido at python.org> wrote:

> I'm still confused. We're talking about a function that compares two
> simple values, right? Where does the sequence of values come from?

it comes from wherever, but the idea is that the function itself is called
in a loop or comprehension, we could require something like:

[ is_close_to(i) for i in seq if abs(i) > abs_tol else abs(i) <= abs_tol]

but I prefer:

[ is_close_to(i, abs_tolerance=abs_tol) for i in seq ]

And it gets worse for the TestCase.assert** - those are designed to act on
a sequence, so you would need to specify both your relative tolerance and
absolute tolerance anyway, if your sequence might have zeros in it.

>  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.

Something like that, yes, but with a cleaner API and better docs ;-)



Christopher Barker, Ph.D.

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/20150127/da215175/attachment.html>

More information about the Python-ideas mailing list