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
API: check_broadcast cannot return None #15209
API: check_broadcast cannot return None #15209
Conversation
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
This looks like a bug. If that is the case, then it needs a change log entry. And a regression test (why didn't we see this failing CI?). But let's wait to hear back from |
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.
This is definitely an oversight as this is handled this way in several other places.. Thanks for finding it.
You know, I realized that By the above reasoning, this change has no user-visible impact. So I'm going to change this to MNT. |
48dad7a
to
1f791c2
Compare
@pllim, if you agree with my assessment, would you please update the labels? |
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.
This test:
astropy/astropy/modeling/tests/test_core.py
Lines 984 to 1004 in dce55cd
def test__validate_input_shapes(): | |
model = models.Gaussian1D() | |
model._n_models = 2 | |
inputs = [mk.MagicMock() for _ in range(3)] | |
argnames = mk.MagicMock() | |
model_set_axis = mk.MagicMock() | |
all_shapes = [mk.MagicMock() for _ in inputs] | |
# Successful validation | |
with mk.patch.object( | |
Model, "_validate_input_shape", autospec=True, side_effect=all_shapes | |
) as mkValidate: | |
with mk.patch.object(core, "check_broadcast", autospec=True) as mkCheck: | |
assert mkCheck.return_value == model._validate_input_shapes( | |
inputs, argnames, model_set_axis | |
) | |
assert mkCheck.call_args_list == [mk.call(*all_shapes)] | |
assert mkValidate.call_args_list == [ | |
mk.call(model, _input, idx, argnames, model_set_axis, True) | |
for idx, _input in enumerate(inputs) | |
] |
def test__validate_input_shapes():
model = models.Gaussian1D()
model._n_models = 2
# Full success
inputs = [np.array([[1, 2], [3, 4]]), np.array([[5, 6], [7, 8]])]
assert (2, 2) == model._validate_input_shapes(inputs, model.inputs, 1)
# Fail check_broadcast
MESSAGE = r"All inputs must have identical shapes or must be scalars"
# Fails because the input shape of the second input has one more axis which
# for which the first input can be broadcasted to
inputs = [np.array([[1, 2], [3, 4]]), np.array([[5, 6], [7, 8], [9, 10]])]
with pytest.raises(ValueError, match=MESSAGE):
model._validate_input_shapes(inputs, model.inputs, 1)
(this will need to be updated to catch the IncompatibleShapeError
)
I agree. |
1f791c2
to
a28571a
Compare
astropy/modeling/core.py
Outdated
) | ||
|
||
return input_shape | ||
return check_broadcast(*all_shapes) |
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.
After examining the IncompatableShapeError
I think I like previous error message better.
For example the test_core
test which was refactored gives the message:
astropy.utils.shapes.IncompatibleShapeError: ((2, 2), 0, (3, 2), 1)
which is a bit opaque to as to what the issue is.
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.
Alright. How about if I raise a new IncompatibleShapeError but with a better explanation?
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.
The current message is actually pretty clear about what users should be doing.
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.
OK, got it. That will make this an API change, though, since IncompatibleShapeError
doesn't support custom error messages, but ValueError
does. Sorry, @pllim!
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.
No worries. Let me know when to update the labels again. 😆 API change needs a change log for sure.
Can you please be more specific on which label needs updating? Thanks! |
Re: labels -- Ah, you mean the change log? If you are changing the exception type that gets raised, it still needs a change log. And as stated above, I don't think we should backport that because that is strictly not backward compatible. |
I mean, remove the Bug label. This should be treated as a MNT-only change. So, no need for a changelog entry. |
So no backport, right? I also will move the milestone to v6 then, ok? |
Depends. Are you really changing the exception type or not? |
Correct, no backport, and v6 milestone is fine. |
I am not changing the exception type. We currently raise an IncompatibleShapeError, and we will still raise an IncompatibleShapeError. (Read #15209 (comment) carefully.) |
a28571a
to
d792c03
Compare
d792c03
to
bf84b7f
Compare
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.
LGTM now, thanks! But I'll let William approve.
Description
_validate_input_shapes
callscheck_broadcast
and compares its return value withNone
, butcheck_broadcast
(as far as I can tell) cannot returnNone
.