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

Allow PixelAccess to use Python __int__ when parsing x and y #5206

Merged
merged 2 commits into from Mar 31, 2021

Conversation

radarhere
Copy link
Member

Resolves #5048

The issue reports that

px = im.load()
px[numpy.int32(5), numpy.int32(5)]

returns

TypeError: an integer is required

This PR calls __int__() on the object passed in, which should provide support for other kinds of objects as well.

@X-Bruce-Y
Copy link

Thank you for making life easier!

@wiredfool
Copy link
Member

Do we need to do anything on PyAccess for this?

@radarhere
Copy link
Member Author

Testing, I find that PyAccess works without this PR. The following code produces no error.

from PIL import Image
import numpy
Image.USE_CFFI_ACCESS = True
im = Image.open("Tests/images/hopper.png")
pix = im.load()
print(pix.__class__)  # <class 'PIL.PyAccess._PyAccess32_3'>
pix[numpy.int32(1), numpy.int32(2)]

@hugovk hugovk merged commit 683affa into python-pillow:master Mar 31, 2021
@radarhere radarhere deleted the numpy branch March 31, 2021 21:09
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.

PixelAccess class does not support Numpy int indexing
4 participants