Re: [Python-ideas] float comparison in doctest
[Sorry for breaking the threading--turns out I didn't have a python-ideas subscription from this address] Just a few followup points I wanted to make to Kevin's post about a proposed +FLOAT_CMP flag for doctest. A better link for the implementation is this PR in Astropy: https://github.com/astropy/astropy/pull/2087 I can't take full credit either--most of the existing code was borrowed (with some small improvements) from the SymPy project. I had started on a similar feature independently, but then borrowed their implementation upon seeing that it was further along than mine. On 12 Aug 2014 04:16, "Terry Reedy" <tjreedy at udel.edu> wrote:
The problem with a simple flag is that almost_equal should sometimes be absolute and sometimes relative and in both cases a parameter in needed. I think there have been vague proposals for a float method, but "a - b < delta" is shorter than "a.almost_equat(b, abs=delta)" and probably easier to understand.
Indeed, that's what I had in mind when I told Kevin that there were still issues with this. There's no obvious way (I can think of at least) to parameterize doctest flags. However, the original immediate purpose of this feature was to handle very small differences in representation of the same value between different platforms, and in that respect it has worked very well. Astropy has a lot of doctests, and many of which have floating point outputs. This +FLOAT_CMP flag enabled removing tons of ellipses from the test outputs, and restoring the full outputs which certainly read better in the docs. For more complete unit tests of course we use assert_almost_equal type functions. That said, if anyone has any ideas for allowing tweaking the tolerances for a doctest flag that would be great. If this otherwise seems like a good idea in general to include in the doctest module I will offer a patch. Erik
On 14 August 2014 01:30, Erik Bray <erik.m.bray@gmail.com> wrote:
That said, if anyone has any ideas for allowing tweaking the tolerances for a doctest flag that would be great. If this otherwise seems like a good idea in general to include in the doctest module I will offer a patch.
I think it sounds like a reasonable idea, even with the "can't be tuned" limitation. It does become a possible use case *for* a doctest flag tuning system, but that doesn't need to be a requirement. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (2)
-
Erik Bray -
Nick Coghlan