mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-28 02:04:36 +03:00
Merge pull request #6394 from radarhere/numpy
Reverted to __array_interface__ with the release of NumPy 1.23
This commit is contained in:
commit
b1e9a3c171
|
@ -1,4 +1,5 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
from packaging.version import parse as parse_version
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
@ -34,9 +35,10 @@ def test_toarray():
|
||||||
test_with_dtype(numpy.float64)
|
test_with_dtype(numpy.float64)
|
||||||
test_with_dtype(numpy.uint8)
|
test_with_dtype(numpy.uint8)
|
||||||
|
|
||||||
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 Image.open("Tests/images/truncated_jpeg.jpg") as im_truncated:
|
||||||
numpy.array(im_truncated)
|
with pytest.raises(OSError):
|
||||||
|
numpy.array(im_truncated)
|
||||||
|
|
||||||
|
|
||||||
def test_fromarray():
|
def test_fromarray():
|
||||||
|
|
|
@ -671,14 +671,9 @@ class Image:
|
||||||
raise ValueError("Could not save to PNG for display") from e
|
raise ValueError("Could not save to PNG for display") from e
|
||||||
return b.getvalue()
|
return b.getvalue()
|
||||||
|
|
||||||
class _ArrayData:
|
@property
|
||||||
def __init__(self, new):
|
def __array_interface__(self):
|
||||||
self.__array_interface__ = new
|
|
||||||
|
|
||||||
def __array__(self, dtype=None):
|
|
||||||
# numpy array interface support
|
# numpy array interface support
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
new = {}
|
new = {}
|
||||||
shape, typestr = _conv_type_shape(self)
|
shape, typestr = _conv_type_shape(self)
|
||||||
new["shape"] = shape
|
new["shape"] = shape
|
||||||
|
@ -690,8 +685,7 @@ class Image:
|
||||||
new["data"] = self.tobytes("raw", "L")
|
new["data"] = self.tobytes("raw", "L")
|
||||||
else:
|
else:
|
||||||
new["data"] = self.tobytes()
|
new["data"] = self.tobytes()
|
||||||
|
return new
|
||||||
return np.array(self._ArrayData(new), dtype)
|
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()]
|
return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user