Skip to content

[Bug]: DeprecationWarning from Pillow 11.3.0 about 'mode' parameter of PIL.Image.fromarray() #30249

@cacti77

Description

@cacti77

Bug summary

Pillow 11.3.0 has deprecated the 'mode' parameter for PIL.Image.fromarray(). The DeprecationWarning causes Azure DevOps builds using matplotlib's plt.figure() to fail when PYTHONWARNINGS=error

Code for reproduction

This stacktrace is from an Azure DevOps Microsoft-hosted Windows agent ('windows-2019' VM image) using Python 3.9.13:

Traceback (most recent call last):
<our code deleted>
    self._fig = plt.figure(figsize=(9, 6))
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py", line 1027, in figure
    manager = new_figure_manager(
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\pyplot.py", line 550, in new_figure_manager
    return _get_backend_mod().new_figure_manager(*args, **kwargs)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 3507, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 3512, in new_figure_manager_given_figure
    return cls.FigureCanvas.new_manager(figure, num)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 1797, in new_manager
    return cls.manager_class.create_with_canvas(cls, figure, num)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 504, in create_with_canvas
    manager = cls(canvas, num, window)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 457, in __init__
    super().__init__(canvas, num)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 2665, in __init__
    tools.add_tools_to_container(self.toolbar)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_tools.py", line 1007, in add_tools_to_container
    container.add_tool(tool, group, position)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backend_bases.py", line 3323, in add_tool
    self.add_toolitem(tool.name, group, position,
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 980, in add_toolitem
    button = NavigationToolbar2Tk._Button(frame, name, image_file, toggle,
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 825, in _Button
    NavigationToolbar2Tk._set_image_for_button(self, b)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 767, in _set_image_for_button
    im_alt = _recolor_icon(im, foreground)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\matplotlib\backends\_backend_tk.py", line 754, in _recolor_icon
    return Image.fromarray(image_data, mode="RGBA")
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\PIL\Image.py", line 3314, in fromarray
    deprecate("'mode' parameter", 13)
  File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\site-packages\PIL\_deprecate.py", line 68, in deprecate
    warnings.warn(
DeprecationWarning: 'mode' parameter is deprecated and will be removed in Pillow 13 (2026-10-15)

Similar failures occur in Linux and Windows on Pythons 3.9 and 3.12.

Actual outcome

DeprecationWarning: 'mode' parameter is deprecated and will be removed in Pillow 13 (2026-10-15)

Expected outcome

No deprecation warning.

Additional information

Our DevOps pipelines started breaking with this on 2 July when pillow (installed via pip) upgraded from 11.2.1 to 11.3.0.

Operating system

Windows

Matplotlib Version

3.9.4

Matplotlib Backend

Not sure, TkAgg?

Python version

3.9.13

Jupyter version

N/A

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions