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

Image.point(lut, mode) no longer accepts numpy.arrays #439

Closed
michel4j opened this issue Dec 10, 2013 · 8 comments
Closed

Image.point(lut, mode) no longer accepts numpy.arrays #439

michel4j opened this issue Dec 10, 2013 · 8 comments

Comments

@michel4j
Copy link

In PIL 1.1.7, you could pass a numpy.array as a look-up-table. However the current version 2.2.1 breaks that behavior by allowing only collections.Sequence instances, which a numpy.array is not.

@aclark4life
Copy link
Member

@minkwe Can you trace this regression back in the commit history (assuming numpy.array should still be supported)?

@michel4j
Copy link
Author

@aclark4life You can find the change at the bottom of da1d715

Essentially operator.isSequenceType was replaced with collections.Sequence probably to support Python 3 which does not have operator.isSequenceType. But I discovered this because it broke my code when I moved from Pillow 1.7.8 to Pillow 2+:

operator.isSequenceType(numpy.array([1]) # True
isinstance(numpy.array([1]), collections.Sequence) # False for both python 2.7 and 3

There is an outstanding bug request to make numpy a collections.Sequence numpy/numpy#2776. However it would be nice if Pillow continues to support numpy.ndarrays until this is fixed or in the alternative the release notes of Pillow should contain a backward incompatibility warning.

@aclark4life
Copy link
Member

OK so Python 3 compat broke numpy.array support, thanks. Is there an operator.isSequenceType equivalent in Python 3, anyone know?

@wiredfool
Copy link
Member

Looks like this is the only place in the code where we're likely to get a numpy.array that's going to trigger this bug. (the other mention is in the resolution tag in tiffs, and I just don't see that being a problem).

I'd propose adding an isSequenceType function into the _util.py file that would specifically check for numpy.arrays.

@aclark4life
Copy link
Member

+1

@wiredfool
Copy link
Member

Also, we need test coverage on this. And the 16bit lut issue as well.

@michel4j
Copy link
Author

What about checking if lut is callable and then assuming it is a sequence. Currently the code checks for sequence first and then assumes it is a function. hasattr(lut,"__call__") will work in both Python 2 and Python 3. This avoids adding numpy specifics.

@wiredfool
Copy link
Member

@minkwe that would work too. though, as callable(lut). or not. We use isinstance(foo, collections.callable) too. I think they all wind up essentially checking hasattr anyway.

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

No branches or pull requests

3 participants