diff --git a/astropy/modeling/core.py b/astropy/modeling/core.py index 2595812fb6eb..0224198f5eb1 100644 --- a/astropy/modeling/core.py +++ b/astropy/modeling/core.py @@ -1061,14 +1061,7 @@ def _validate_input_shapes(self, inputs, argnames, model_set_axis): ) ) - try: - input_shape = check_broadcast(*all_shapes) - except IncompatibleShapeError as err: - raise ValueError( - "All inputs must have identical shapes or must be scalars." - ) from err - - return input_shape + return check_broadcast(*all_shapes) def input_shape(self, inputs): """Get input shape for bounding_box evaluation.""" diff --git a/astropy/modeling/tests/test_models.py b/astropy/modeling/tests/test_models.py index 0593770ff6f8..19e220d23f6c 100644 --- a/astropy/modeling/tests/test_models.py +++ b/astropy/modeling/tests/test_models.py @@ -29,7 +29,7 @@ ) from astropy.modeling.separable import separability_matrix from astropy.tests.helper import assert_quantity_allclose -from astropy.utils import NumpyRNGContext, minversion +from astropy.utils import IncompatibleShapeError, NumpyRNGContext, minversion from astropy.utils.compat.optional_deps import HAS_SCIPY from .example_models import models_1D, models_2D @@ -120,6 +120,12 @@ def test_inconsistent_input_shapes(): y.shape = (1, 10) result = g(x, y) assert result.shape == (10, 10) + # incompatible shapes do _not_ work + g = Gaussian2D() + x = np.arange(-1.0, 1, 0.2) + y = np.arange(-1.0, 1, 0.1) + with pytest.raises(IncompatibleShapeError): + g(x, y) def test_custom_model_bounding_box():