Skip to content

fix: keep shape validation in _normalize_output for non-float output - #1148

Merged
henryiii merged 1 commit into
developfrom
fix/normalize-output-shape
Aug 29, 2026
Merged

fix: keep shape validation in _normalize_output for non-float output#1148
henryiii merged 1 commit into
developfrom
fix/normalize-output-shape

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 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.

@ikrommyd ikrommyd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread tests/test_cost.py Outdated
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)


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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
henryiii force-pushed the fix/normalize-output-shape branch from e140834 to a7ebce1 Compare August 28, 2026 22:34
@henryiii
henryiii merged commit dbf3e48 into develop Aug 29, 2026
9 checks passed
@henryiii
henryiii deleted the fix/normalize-output-shape branch August 29, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants