8000 Merge pull request #22766 from tacaswell/fix_pillow_compat · QuLogic/matplotlib@4f5b310 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f5b310

Browse files
authored
Merge pull request matplotlib#22766 from tacaswell/fix_pillow_compat
FIX: account for constant deprecations in Pillow 9.1
2 parents 8b1881f + bd6f04b commit 4f5b310

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
@@ -138,6 +138,9 @@ stages:
138138
- script: env
139139
displayName: 'print env'
140140

141+
- script: pip list
142+
displayName: 'print pip'
143+
141144
- bash: |
142145
PYTHONFAULTHANDLER=1 python -m pytest --junitxml=junit/test-results.xml -raR --maxfail=50 --timeout=300 --durations=25 --cov-report= --cov=lib -n 2 ||
143146
[[ "$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
@@ -468,14 +469,15 @@ def grab_frame(self, **savefig_kwargs):
468469
def finish(self):
469470
# Call run here now that all frame grabbing is done. All temp files
470471
# are available to be assembled.
471-
self._run()
472-
super().finish() # Will call clean-up
473-
474-
def _cleanup(self): # Inline to finish() once cleanup() is removed.
475-
super()._cleanup()
476-
if self._tmpdir:
477-
_log.debug('MovieWriter: clearing temporary path=%s', self._tmpdir)
478-
self._tmpdir.cleanup()
472+
try:
473+
self._run()
474+
super().finish()
475+
finally:
476+
if self._tmpdir:
477+
_log.debug(
478+
'MovieWriter: clearing temporary path=%s', self._tmpdir
479+
)
480+
self._tmpdir.cleanup()
479481

480482

481483
@writers.register('pillow')

lib/matplotlib/backends/backend_pdf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,13 @@ def _writeImg(self, data, id, smask=None):
17001700
# Convert to indexed color if there are 256 colors or fewer
17011701
# This can significantly reduce the file size
17021702
num_colors = len(img_colors)
1703-
img = img.convert(mode='P', dither=Image.NONE,
1704-
palette=Image.ADAPTIVE, colors=num_colors)
1703+
# These constants were converted to IntEnums and deprecated in
1704+
# Pillow 9.2
1705+
dither = getattr(Image, 'Dither', Image).NONE
1706+
pmode = getattr(Image, 'Palette', Image).ADAPTIVE
1707+
img = img.convert(
1708+
mode='P', dither=dither, palette=pmode, colors=num_colors
1709+
)
17051710
png_data, bit_depth, palette = self._writePng(img)
17061711
if bit_depth is None or palette is None:
17071712
raise RuntimeError("invalid PNG header")

0 commit comments

Comments
 (0)
0