Skip to content

Commit

Permalink
Merge pull request #4181 from pwohlhart/patch-1
Browse files Browse the repository at this point in the history
Better error messaging in PIL.Image.fromarray
  • Loading branch information
radarhere committed Nov 30, 2019
2 parents a776255 + 19a8a39 commit 08cad40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Tests/test_image_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ def test(mode):
self.assertEqual(test("RGB"), ("RGB", (128, 100), True))
self.assertEqual(test("RGBA"), ("RGBA", (128, 100), True))
self.assertEqual(test("RGBX"), ("RGBA", (128, 100), True))

# Test mode is None with no "typestr" in the array interface
with self.assertRaises(TypeError):
wrapped = Wrapper(test("L"), {"shape": (100, 128)})
Image.fromarray(wrapped)
5 changes: 4 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2570,9 +2570,12 @@ def fromarray(obj, mode=None):
if mode is None:
try:
typekey = (1, 1) + shape[2:], arr["typestr"]
mode, rawmode = _fromarray_typemap[typekey]
except KeyError:
raise TypeError("Cannot handle this data type")
try:
mode, rawmode = _fromarray_typemap[typekey]
except KeyError:
raise TypeError("Cannot handle this data type: %s, %s" % typekey)
else:
rawmode = mode
if mode in ["1", "L", "I", "P", "F"]:
Expand Down

0 comments on commit 08cad40

Please sign in to comment.