8000 Backport PR #22766: FIX: account for constant deprecations in Pillow 9.1 · meeseeksmachine/matplotlib@0205618 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0205618

Browse files
oscargusmeeseeksmachine
authored andcommitted
Backport PR matplotlib#22766: FIX: account for constant deprecations in Pillow 9.1
1 parent 9c603cc commit 0205618

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
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/animation.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# * Can blit be enabled for movies?
1818
# * Need to consider event sources to allow clicking through multiple figures
1919

20+
2021
import abc
2122
import base64
2223
import contextlib
@@ -481,14 +482,15 @@ def grab_frame(self, **savefig_kwargs):
481482
def finish(self):
482483
# Call run here now that all frame grabbing is done. All temp files
483484
# are available to be assembled.
484-
self._run()
485-
super().finish() # Will call clean-up
486-
487-
def _cleanup(self): # Inline to finish() once cleanup() is removed.
488-
super()._cleanup()
489-
if self._tmpdir:
490-
_log.debug('MovieWriter: clearing temporary path=%s', self._tmpdir)
491-
self._tmpdir.cleanup()
485+
try:
486+
self._run()
487+
super().finish()
488+
finally:
489+
if self._tmpdir:
490+
_log.debug(
491+
'MovieWriter: clearing temporary path=%s', self._tmpdir
492+
)
493+
self._tmpdir.cleanup()
492494

493495

494496
@writers.register('pillow')

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)
0