Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved putdata() documentation and data handling #5910

Merged
merged 3 commits into from Dec 28, 2021

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Dec 27, 2021

Resolves #5858

  1. Clarify that putdata() should receive a flattened sequence, rather than the 2D sequence that the user is trying in the issue.

I have drawn inspiration from the docstring for getdata()

Pillow/src/PIL/Image.py

Lines 1277 to 1282 in 11c536b

def getdata(self, band=None):
"""
Returns the contents of this image as a sequence object
containing pixel values. The sequence object is flattened, so
that values for line one follow directly after the values of
line zero, and so on.

  1. Raise an error if the sequence is not flattened.

>>> from PIL import Image
>>> im = Image.new("L", (1, 1), 0)
>>> im.putdata([2.0])
>>> print(im.getpixel((0, 0)))

At the moment, in Python 3.9, this returns 2, and in Python 3.10, this returns 0. I've added a commit here to consistently return 2.

@radarhere radarhere changed the title Clarified that the sequence object for putdata() should be flattened Improved putdata() documentation and casting Dec 27, 2021
@radarhere radarhere changed the title Improved putdata() documentation and casting Improved putdata() documentation and data handling Dec 27, 2021
@hugovk hugovk merged commit 8e631e4 into python-pillow:main Dec 28, 2021
51 checks passed
@radarhere radarhere deleted the putdata branch Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants