Skip to content
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

Enforce bins in config and template to match #144

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions alea/template_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,15 @@ def _check_binning(self, h, histogram_info: str):
logging.debug("expected_bin_edges: " + str(expected_bin_edges))
logging.debug("seen_bin_edges: " + str(seen_bin_edges))
logging.debug("h.bin_edges type" + str(h.bin_edges))
err_msg = (
f"Axis {axis_i:d} of histogram {histogram_info} "
f"has bin edges {seen_bin_edges}, but expected {expected_bin_edges}."
)
if len(seen_bin_edges) != len(expected_bin_edges):
raise ValueError(
f"Axis {axis_i:d} of histogram {histogram_info} "
f"has {len(seen_bin_edges)} bin edges, but expected {expected_bin_edges}."
)
try:
np.testing.assert_almost_equal(seen_bin_edges, expected_bin_edges, decimal=2)
except AssertionError:
logging.warn(
f"Axis {axis_i:d} of histogram {histogram_info} "
f"has bin edges {seen_bin_edges}, but expected {expected_bin_edges}. "
"Since length matches, setting it expected values..."
)
h.bin_edges[axis_i] = expected_bin_edges
raise ValueError(err_msg)
np.testing.assert_almost_equal(
seen_bin_edges, expected_bin_edges, decimal=2, err_msg=err_msg
)

@property
def format_named_parameters(self):
Expand Down
Loading