Merge pull request #1 from radarhere/fromarray

Allow for arr KeyError
This commit is contained in:
pwohlhart 2019-10-29 14:09:18 -07:00 committed by GitHub
commit 19a8a39ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -52,3 +52,8 @@ class TestImageArray(PillowTestCase):
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)

View File

@ -2631,6 +2631,9 @@ def fromarray(obj, mode=None):
if mode is None:
try:
typekey = (1, 1) + shape[2:], arr["typestr"]
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)