fix: Account for fuzzy edge values in rebinning with edges#999
Merged
Conversation
Member
|
Thanks for catching that @riga! |
Member
|
The fix sounds good. Also, should this be an assert, or a raise AssertionError (or another Error)? Would we really want this check skipped if running without assertions? |
Contributor
Author
|
Good point. Imho, all of the checks should be mandatory. I'm changing this as well. |
| ) | ||
| if not all_close: | ||
| msg = "Edges must be in the axis" | ||
| raise ValueError(msg) |
Member
There was a problem hiding this comment.
Could we emit the offending edge? It would make for easier debug by users. Something like
f"Edge(s) {missing_edges} not found in the axis. Nearest available edges are ..."
Contributor
Author
There was a problem hiding this comment.
Sure, just added that.
Member
|
I've found another (unrelated) bug, so likely will be making a patch release in the near future; I'll backport this too. |
Contributor
Author
|
I noticed that the test should actually compare against the true (exact) edges, which failed the tests. Should be fixed now. |
d1f3830 to
dc244ee
Compare
Member
|
Thanks! |
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.
This PR fixes the rebinning of axes given a sequence of new edges that was recently added by #977.
Background
We recently discovered the new rebinning feature that only requires new edges values rather than bin count "groups", which is great! It requires that the requested edges coincide (that's where the problem is) with old ones so that bin content merging is logically unambiguous. However, we ran into an edge case where a single, new edge value is subject to float precision effects (e.g.
1.200000000000001).The issue
Currently, this causes a bug in that the newly computed edges are missing an entry, resulting in axes dropping a bin. I extended the
test_rebin_1dtest case to use a fuzzy edge value, showing that the assertion inboost-histogram/src/boost_histogram/tag.py
Lines 190 to 202 in fdfdae1
passes due to
np.isclose, but the subsequent index lookup via an exactnp.isinfails: N edges were requested, but the rebinned axis only has N - 1.Fix
I already prepared and tested a working fix,
essentially storing the argmin results, doing the assertion, and then computing new edges with them.
If you agree, I can add the commit to this PR, but I thought it might be easier to run the test case and see that it indeed fails where it should/shouldn't.