-
Notifications
You must be signed in to change notification settings - Fork 24
fix: Account for fuzzy edge values in rebinning with edges #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Thanks for catching that @riga! |
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? |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, just added that.
I've found another (unrelated) bug, so likely will be making a patch release in the near future; I'll backport this too. |
I noticed that the test should actually compare against the true (exact) edges, which failed the tests. Should be fixed now. |
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_1d
test 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.isin
fails: 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.