Repository navigation
Let Image.fromarray infer mode for 2D float32 thumbnail arrays for Pillow >= 13 compatibility. - #11256
Merged
Conversation
copybara-service
Bot
force-pushed
the
test_1018508067
branch
from
November 11, 2026 13:02
c4ff66d to
fdd146c
Compare
…llow >= 13 compatibility. Pillow 13.0.0 [redeprecates](https://pillow.readthedocs.io/en/latest/releasenotes/13.0.0.html#image-fromarray-mode-parameter) the `mode` parameter in `Image.fromarray` and raises `ValueError: Invalid mode for data type` when `mode='L'` is passed with a 2D `np.float32` array. In `create_thumbnail`, 1-channel `np.float32` images squeezed to 2D previously fell into the `else: mode = 'L'` branch. Handle `np.float32` alongside `np.uint16` for 1-channel images by passing `mode=None` (which infers `'F'` for 2D `float32` arrays) and converting to `'RGB'` via `_postprocess_convert_rgb` before saving the PNG thumbnail. PiperOrigin-RevId: 1019097631
copybara-service
Bot
force-pushed
the
test_1018508067
branch
from
November 11, 2026 13:17
fdd146c to
a96809c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Let Image.fromarray infer mode for 2D float32 thumbnail arrays for Pillow >= 13 compatibility.
Pillow 13.0.0 redeprecates the
modeparameter inImage.fromarrayand raisesValueError: Invalid mode for data typewhenmode='L'is passed with a 2Dnp.float32array. Increate_thumbnail, 1-channelnp.float32images squeezed to 2D previously fell into theelse: mode = 'L'branch.Handle
np.float32alongsidenp.uint16for 1-channel images by passingmode=None(which infers'F'for 2Dfloat32arrays) and converting to'RGB'via_postprocess_convert_rgbbefore saving the PNG thumbnail.