fix: keep shape validation in _normalize_output for non-float output - #1148
Merged
Conversation
ikrommyd
approved these changes
Aug 6, 2026
ikrommyd
left a comment
Member
There was a problem hiding this comment.
Only left a comment regarding the testing which is a take it or leave it. I normally would test this from a higher level or not test it at all as the change looks trivial to me.
Comment on lines
+1794
to
+1807
| def test_normalize_output_wrong_shape_int(): | ||
| # an integer array with the wrong shape must still raise the descriptive | ||
| # shape error instead of silently slipping through the float early-return | ||
| from iminuit.cost import _normalize_output | ||
|
|
||
| x = np.array([1, 2], dtype=int) | ||
| with pytest.warns(PerformanceWarning): | ||
| with pytest.raises( | ||
| ValueError, | ||
| match=r"output of model has shape \(2,\), but \(3,\) is required", | ||
| ): | ||
| _normalize_output(list(x), "model", 3) | ||
|
|
||
|
|
Member
There was a problem hiding this comment.
I normally would not add a test for an internal _normalize_output function and I would have created a test with a real model that actually reproduces the problem. Take it or leave it.
A model that returned a non-float sequence took an early return before the shape check, so a wrong shape passed silently. Convert to float and continue to the shape check. Assisted-by: ClaudeCode:claude-opus-5
henryiii
force-pushed
the
fix/normalize-output-shape
branch
from
August 28, 2026 22:34
e140834 to
a7ebce1
Compare
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.
🤖 AI text below 🤖
Split out of #1137.
A model that returned a non-float sequence took an early return before the shape check, so a wrong shape passed silently. The value is now converted to float and falls through to the shape check.