Skip to content

Commit 108d07d

Browse files
authored
Merge pull request astropy#19152 from neutrinoceros/modeling/19126-2
BUG: avoid mutation of shape attibutes (modeling, 2/2)
2 parents 2c696cd + 8616ebc commit 108d07d

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎astropy/modeling/parameters.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def shape(self, value):
464464
if value not in ((), (1,)):
465465
raise ValueError("Cannot assign this shape to a scalar quantity")
466466
else:
467-
self.value.shape = value
467+
self.value = np.reshape(self.value, value)
468468

469469
@property
470470
def size(self):

‎astropy/modeling/tests/test_constraints.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,10 @@ def test_2d_model(fitter):
586586
Y = np.linspace(-1, 7, 200)
587587
x, y = np.meshgrid(X, Y)
588588
z = gauss2d(x, y)
589-
w = np.ones(x.size)
590-
w.shape = x.shape
589+
w = np.ones(x.shape)
591590

592591
with NumpyRNGContext(1234567890):
593-
n = np.random.randn(x.size)
594-
n.shape = x.shape
592+
n = np.random.randn(*x.shape)
595593
m = fitter(gauss2d, x, y, z + 2 * n, weights=w)
596594
assert_allclose(m.parameters, gauss2d.parameters, rtol=0.05)
597595
m = fitter(gauss2d, x, y, z + 2 * n, weights=None)

‎astropy/modeling/tests/test_models.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def test_inconsistent_input_shapes():
118118
# check scalar input broadcasting works
119119
assert np.abs(g(x, 0) - g(x, 0 * x)).sum() == 0
120120
# and that array broadcasting works
121-
x.shape = (10, 1)
122-
y.shape = (1, 10)
121+
x = x.reshape((10, 1))
122+
y = y.reshape((1, 10))
123123
result = g(x, y)
124124
assert result.shape == (10, 10)
125125
# incompatible shapes do _not_ work

0 commit comments

Comments
 (0)