mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Remove warning if NumPy failed to raise an error during conversion
This commit is contained in:
parent
d6cfebd016
commit
e382ebed3a
|
@ -47,7 +47,7 @@ def test_toarray() -> None:
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(OSError):
|
||||||
numpy.array(im_truncated)
|
numpy.array(im_truncated)
|
||||||
else:
|
else:
|
||||||
with pytest.warns(UserWarning):
|
with pytest.warns(DeprecationWarning):
|
||||||
numpy.array(im_truncated)
|
numpy.array(im_truncated)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -724,24 +724,12 @@ class Image:
|
||||||
def __array_interface__(self) -> dict[str, str | bytes | int | tuple[int, ...]]:
|
def __array_interface__(self) -> dict[str, str | bytes | int | tuple[int, ...]]:
|
||||||
# numpy array interface support
|
# numpy array interface support
|
||||||
new: dict[str, str | bytes | int | tuple[int, ...]] = {"version": 3}
|
new: dict[str, str | bytes | int | tuple[int, ...]] = {"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(str(e))
|
|
||||||
raise
|
|
||||||
new["shape"], new["typestr"] = _conv_type_shape(self)
|
new["shape"], new["typestr"] = _conv_type_shape(self)
|
||||||
return new
|
return new
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user