Skip to content

Commit 1ff0fb4

Browse files
authored
Merge pull request #7034 from radarhere/array_interface
2 parents 20293e1 + 6a93186 commit 1ff0fb4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Tests/test_numpy.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from PIL import Image
66

7-
from .helper import assert_deep_equal, assert_image, hopper
7+
from .helper import assert_deep_equal, assert_image, hopper, skip_unless_feature
88

99
numpy = pytest.importorskip("numpy", reason="NumPy not installed")
1010

@@ -219,6 +219,13 @@ def test_zero_size():
219219
assert im.size == (0, 0)
220220

221221

222+
@skip_unless_feature("libtiff")
223+
def test_load_first():
224+
with Image.open("Tests/images/g4_orientation_5.tif") as im:
225+
a = numpy.array(im)
226+
assert a.shape == (88, 590)
227+
228+
222229
def test_bool():
223230
# https://github.com/python-pillow/Pillow/issues/2044
224231
a = numpy.zeros((10, 2), dtype=bool)

src/PIL/Image.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,7 @@ def _repr_png_(self):
686686
@property
687687
def __array_interface__(self):
688688
# numpy array interface support
689-
new = {}
690-
shape, typestr = _conv_type_shape(self)
691-
new["shape"] = shape
692-
new["typestr"] = typestr
693-
new["version"] = 3
689+
new = {"version": 3}
694690
try:
695691
if self.mode == "1":
696692
# Binary images need to be extended from bits to bytes
@@ -709,6 +705,7 @@ def __array_interface__(self):
709705
if parse_version(numpy.__version__) < parse_version("1.23"):
710706
warnings.warn(e)
711707
raise
708+
new["shape"], new["typestr"] = _conv_type_shape(self)
712709
return new
713710

714711
def __getstate__(self):

0 commit comments

Comments
 (0)