Skip to content

Commit 4448cd0

Browse files
committed
TST: avoid mutating ndarray.shape attributes
1 parent 57cd1e4 commit 4448cd0

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

unyt/tests/test_array_functions.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,8 @@ def test_dot_vectors():
367367
],
368368
)
369369
def test_dot_matrices(out):
370-
a = np.arange(9) * cm
371-
a.shape = (3, 3)
372-
b = np.arange(9) * s
373-
b.shape = (3, 3)
370+
a = np.reshape(np.arange(9), (3, 3)) * cm
371+
b = np.reshape(np.arange(9), (3, 3)) * s
374372

375373
res = np.dot(a, b, out=out)
376374

@@ -422,10 +420,8 @@ def test_dot_mixed_ndarray_unyt_array():
422420

423421

424422
def test_invalid_dot_matrices():
425-
a = np.arange(9) * cm
426-
a.shape = (3, 3)
427-
b = np.arange(9) * s
428-
b.shape = (3, 3)
423+
a = np.reshape(np.arange(9), (3, 3))
424+
b = np.reshape(np.arange(9), (3, 3)) * s
429425

430426
out = np.empty((3, 3), dtype=np.int_, order="C") * s**2
431427
res = np.dot(a, b, out=out)
@@ -473,8 +469,7 @@ def test_linalg_inv():
473469

474470

475471
def test_linalg_tensorinv():
476-
a = np.eye(4 * 6) * cm
477-
a.shape = (4, 6, 8, 3)
472+
a = np.reshape(np.eye(4 * 6), (4, 6, 8, 3)) * cm
478473
ia = np.linalg.tensorinv(a)
479474
assert 1 * ia.units == 1 / cm
480475

0 commit comments

Comments
 (0)