mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 09:26:16 +03:00
Merge pull request #6594 from radarhere/numpy
This commit is contained in:
commit
c2efd60e22
|
@ -35,10 +35,13 @@ def test_toarray():
|
||||||
test_with_dtype(numpy.float64)
|
test_with_dtype(numpy.float64)
|
||||||
test_with_dtype(numpy.uint8)
|
test_with_dtype(numpy.uint8)
|
||||||
|
|
||||||
if parse_version(numpy.__version__) >= parse_version("1.23"):
|
|
||||||
with Image.open("Tests/images/truncated_jpeg.jpg") as im_truncated:
|
with Image.open("Tests/images/truncated_jpeg.jpg") as im_truncated:
|
||||||
|
if parse_version(numpy.__version__) >= parse_version("1.23"):
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(OSError):
|
||||||
numpy.array(im_truncated)
|
numpy.array(im_truncated)
|
||||||
|
else:
|
||||||
|
with pytest.warns(UserWarning):
|
||||||
|
numpy.array(im_truncated)
|
||||||
|
|
||||||
|
|
||||||
def test_fromarray():
|
def test_fromarray():
|
||||||
|
|
|
@ -679,12 +679,24 @@ class Image:
|
||||||
new["shape"] = shape
|
new["shape"] = shape
|
||||||
new["typestr"] = typestr
|
new["typestr"] = typestr
|
||||||
new["version"] = 3
|
new["version"] = 3
|
||||||
|
try:
|
||||||
if self.mode == "1":
|
if self.mode == "1":
|
||||||
# Binary images need to be extended from bits to bytes
|
# Binary images need to be extended from bits to bytes
|
||||||
# See: https://github.com/python-pillow/Pillow/issues/350
|
# See: https://github.com/python-pillow/Pillow/issues/350
|
||||||
new["data"] = self.tobytes("raw", "L")
|
new["data"] = self.tobytes("raw", "L")
|
||||||
else:
|
else:
|
||||||
new["data"] = self.tobytes()
|
new["data"] = self.tobytes()
|
||||||
|
except Exception as e:
|
||||||
|
if not isinstance(e, (MemoryError, RecursionError)):
|
||||||
|
try:
|
||||||
|
import numpy
|
||||||
|
from packaging.version import parse as parse_version
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if parse_version(numpy.__version__) < parse_version("1.23"):
|
||||||
|
warnings.warn(e)
|
||||||
|
raise
|
||||||
return new
|
return new
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user