Skip to content

Commit 2182782

Browse files
committed
Use reshape() instead of setting NumPy array shape directly
1 parent 92e0e5f commit 2182782

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

‎Tests/test_numpy.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def to_image(dtype: npt.DTypeLike, bands: int = 1, boolean: int = 0) -> Image.Im
2424
if bands == 1:
2525
if boolean:
2626
data = (0, 255) * 50
27-
a = numpy.array(data, dtype=dtype)
28-
a.shape = TEST_IMAGE_SIZE
27+
a = numpy.array(data, dtype=dtype).reshape(TEST_IMAGE_SIZE)
2928
i = Image.fromarray(a)
3029
assert i.get_flattened_data() == data
3130
else:
32-
a = numpy.array([[x] * bands for x in data], dtype=dtype)
33-
a.shape = TEST_IMAGE_SIZE[0], TEST_IMAGE_SIZE[1], bands
34-
i = Image.fromarray(a)
31+
a2 = numpy.array([[x] * bands for x in data], dtype=dtype).reshape(
32+
TEST_IMAGE_SIZE[0], TEST_IMAGE_SIZE[1], bands
33+
)
34+
i = Image.fromarray(a2)
3535
assert i.get_flattened_data(0) == tuple(range(100))
3636
return i
3737

@@ -133,8 +133,7 @@ def test_save_tiff_uint16() -> None:
133133
pixel_value = 0x1234
134134
a = numpy.array(
135135
[pixel_value] * TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1], dtype=numpy.uint16
136-
)
137-
a.shape = TEST_IMAGE_SIZE
136+
).reshape(TEST_IMAGE_SIZE)
138137
img = Image.fromarray(a)
139138

140139
assert img.getpixel((0, 0)) == pixel_value

0 commit comments

Comments
 (0)