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 2 commits into from Mar 31, 2021


Copy link

Resolves #5048

The issue reports that

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


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.

Copy link

Thank you for making life easier!

Copy link

Do we need to do anything on PyAccess for this?

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
im ="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
None yet
None yet

Successfully merging this pull request may close these issues.

PixelAccess class does not support Numpy int indexing
4 participants