Skip to content

Commit e6af31e

Browse files
committed
Deprecate fromarray mode argument
1 parent a3d91cb commit e6af31e

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

Tests/test_image_array.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def __init__(self, arr_params: dict[str, Any]) -> None:
101101

102102
with pytest.raises(ValueError):
103103
wrapped = Wrapper({"shape": (1, 1), "strides": (1, 1)})
104-
Image.fromarray(wrapped, "L")
104+
with pytest.warns(DeprecationWarning):
105+
Image.fromarray(wrapped, "L")
105106

106107

107108
def test_fromarray_palette() -> None:
@@ -110,7 +111,8 @@ def test_fromarray_palette() -> None:
110111
a = numpy.array(i)
111112

112113
# Act
113-
out = Image.fromarray(a, "P")
114+
with pytest.warns(DeprecationWarning):
115+
out = Image.fromarray(a, "P")
114116

115117
# Assert that the Python and C palettes match
116118
assert out.palette is not None

docs/deprecations.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ Image.Image.get_child_images()
193193
method uses an image's file pointer, and so child images could only be retrieved from
194194
an :py:class:`PIL.ImageFile.ImageFile` instance.
195195

196+
Image.fromarray mode parameter
197+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
198+
199+
.. deprecated:: 11.3.0
200+
201+
The ``mode`` parameter in :py:meth:`~PIL.Image.fromarray()` has been deprecated. The
202+
mode can be automatically determined from the object's shape and type instead.
203+
196204
Removed features
197205
----------------
198206

docs/releasenotes/11.3.0.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ TODO
2323
Deprecations
2424
============
2525

26-
TODO
27-
^^^^
26+
Image.fromarray mode parameter
27+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2828

29-
TODO
29+
The ``mode`` parameter in :py:meth:`~PIL.Image.fromarray()` has been deprecated. The
30+
mode can be automatically determined from the object's shape and type instead.
3031

3132
API changes
3233
===========

src/PIL/Image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3272,7 +3272,7 @@ def fromarray(obj: SupportsArrayInterface, mode: str | None = None) -> Image:
32723272
32733273
:param obj: Object with array interface
32743274
:param mode: Optional mode to use when reading ``obj``. Will be determined from
3275-
type if ``None``.
3275+
type if ``None``. Deprecated.
32763276
32773277
This will not be used to convert the data after reading, but will be used to
32783278
change how the data is read::
@@ -3307,6 +3307,7 @@ def fromarray(obj: SupportsArrayInterface, mode: str | None = None) -> Image:
33073307
msg = f"Cannot handle this data type: {typekey_shape}, {typestr}"
33083308
raise TypeError(msg) from e
33093309
else:
3310+
deprecate("'mode' parameter", 13)
33103311
rawmode = mode
33113312
if mode in ["1", "L", "I", "P", "F"]:
33123313
ndmax = 2

0 commit comments

Comments
 (0)