cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-71385: add relative delta parameter for assertAlmostEqual and assertNotAlmostEqual

Open wehlgrundspitze opened this issue 3 years ago • 5 comments
trafficstars

relative delta keyword for assertAlmostEqual and assertNotAlmostEqual #71385

gh-71385: a keyword "rel_delta" is introduced to the functions assertAlmostEqual and assertNotAlmostEqual to allow comparisons based on the relative difference of two values

more detailed history in the corresponding issue #71385

wehlgrundspitze avatar Sep 16 '22 21:09 wehlgrundspitze

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

bedevere-bot avatar Sep 16 '22 21:09 bedevere-bot

All commit authors signed the Contributor License Agreement.
CLA signed

cpython-cla-bot[bot] avatar Sep 16 '22 21:09 cpython-cla-bot[bot]

@wehlgrundspitze your PR title should be: gh-71385: add relative delta parameter for assertAlmostEqual and assertNotAlmostEqual

sobolevn avatar Sep 21 '22 12:09 sobolevn

Thanks for your comments and feedback. I implemented them all and hope for acceptance.

wehlgrundspitze avatar Oct 08 '22 22:10 wehlgrundspitze

It seems to me that both existing and modified code don't have defined behavior when one (or both) input are either float('nan') or float('inf'). Especially assertNotAlmostEqual will fail when both of it's arguments are NaNs. This is different than math.isclose() and potentially confusing. https://docs.python.org/3/library/math.html#math.isclose Either we fix it or at least add a note in docstring.

chalggg avatar Oct 16 '22 13:10 chalggg

That was a great remark. I fixed the algorithm to handle +-inf and NaN according to IEEE 754 (and therefore consistent with math.isclose) and wrote an additional test about it.

wehlgrundspitze avatar Oct 16 '22 21:10 wehlgrundspitze