Skip to content

Commit b042615

Browse files
authored
Merge pull request #22780 from meeseeksmachine/auto-backport-of-pr-22766-on-v3.5.x
Backport PR #22766 on branch v3.5.x (FIX: account for constant deprecations in Pillow 9.1)
2 parents ad318d9 + 520120b commit b042615

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ stages:
134134
- script: env
135135
displayName: 'print env'
136136

137+
- script: pip list
138+
displayName: 'print pip'
139+
137140
- bash: |
138141
PYTHONFAULTHANDLER=1 python -m pytest --junitxml=junit/test-results.xml -raR --maxfail=50 --timeout=300 --durations=25 --cov-report= --cov=lib -n 2 ||
139142
[[ "$PYTHON_VERSION" = 'Pre' ]]

lib/matplotlib/backends/backend_pdf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,13 @@ def _writeImg(self, data, id, smask=None):
17181718
# Convert to indexed color if there are 256 colors or fewer
17191719
# This can significantly reduce the file size
17201720
num_colors = len(img_colors)
1721-
img = img.convert(mode='P', dither=Image.NONE,
1722-
palette=Image.ADAPTIVE, colors=num_colors)
1721+
# These constants were converted to IntEnums and deprecated in
1722+
# Pillow 9.2
1723+
dither = getattr(Image, 'Dither', Image).NONE
1724+
pmode = getattr(Image, 'Palette', Image).ADAPTIVE
1725+
img = img.convert(
1726+
mode='P', dither=dither, palette=pmode, colors=num_colors
1727+
)
17231728
png_data, bit_depth, palette = self._writePng(img)
17241729
if bit_depth is None or palette is None:
17251730
raise RuntimeError("invalid PNG header")

0 commit comments

Comments
 (0)