Add equal_to_approx matcher for approximate numeric assertions#39443
Open
SreeramaYeshwanthGowd wants to merge 1 commit into
Open
Add equal_to_approx matcher for approximate numeric assertions#39443SreeramaYeshwanthGowd wants to merge 1 commit into
SreeramaYeshwanthGowd wants to merge 1 commit into
Conversation
equal_to only supports exact equality, so tests over floating point pipeline output had to supply a custom equals_fn. Add equal_to_approx, which compares real number elements (including numbers nested in tuples or lists) with math.isclose using configurable rel_tol and abs_tol, reusing the existing equal_to matching. Includes unit tests and a CHANGES.md entry. Fixes apache#18028
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
|
Assigning reviewers: R: @tvalentyn for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
assert_thatmatchers only offer exact equality throughequal_to.Pipelines that produce floating point results are awkward to assert, because
callers have to hand write an
equals_fnin every test. Issue #18028 asks toexpand the set of matchers.
Solution
Add
equal_to_approx, anassert_thatmatcher that behaves likeequal_toforordering and membership but compares real number elements, including numbers
nested in tuples or lists, with
math.iscloseusing configurablerel_tolandabs_tol. All other elements are compared with==. It is a thin wrapper overthe existing
equal_to(equals_fn=...)mechanism and adds no new dependency.Testing
Added unit tests in
util_test.pycovering values within and outside tolerance(including a nested value outside tolerance), nested tuples and lists,
rel_toland
abs_tol, non numeric passthrough, and an empty PCollection.Fixes #18028
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.