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

Pillow 8.3 and NumPy #5571

Closed
doublex opened this issue Jul 1, 2021 · 13 comments · Fixed by #5572
Closed

Pillow 8.3 and NumPy #5571

doublex opened this issue Jul 1, 2021 · 13 comments · Fixed by #5572

Comments

@doublex
Copy link

doublex commented Jul 1, 2021

Throws exception with Pillow 8.3: TypeError: __array__() takes 1 positional argument but 2 were given

with PIL.Image.open(filepath) as img:
    numpy.array( img, dtype=numpy.float32 )
@radarhere
Copy link
Member

What version of Python are you using? What version of numpy?

@vgrabovets
Copy link

vgrabovets commented Jul 1, 2021

Same problem here.
Python 3.7.4
numpy 1.21.0

workaround:

with PIL.Image.open(filepath) as img:
    numpy.array(img).astype(np.float32)

@t-vi
Copy link
Contributor

t-vi commented Jul 1, 2021

Works with just about anything. The problem is that pillow newly implemented __array__, but only without arguments. Numpy requires __array__ to take an optional dtype argument. This is used e.g. by numpy.array when the user passes a dtype argument. This should be with just about any numpy/python version.

@doublex
Copy link
Author

doublex commented Jul 1, 2021

fails with python 3.8 + 3.9, numpy 1.20 + 1.21

@t-vi
Copy link
Contributor

t-vi commented Jul 1, 2021

I'll send a patch.

@carmocca
Copy link

carmocca commented Jul 1, 2021

We are seeing errors in 3.{6,7,8,9}

@ericpre
Copy link

ericpre commented Jul 1, 2021

Same issue in https://github.com/hyperspy/hyperspy/runs/2961516889 for all python version >=3.6 using the imageio library:

                # Apply palette
>               frame_paletted = np.array(im, np.uint8)
E               TypeError: __array__() takes 1 positional argument but 2 were given

/opt/hostedtoolcache/Python/3.9.5/x64/lib/python3.9/site-packages/imageio/plugins/pillow.py:745: TypeError

The python 3.6 build is with numpy 1.17.1

@cgebbe
Copy link

cgebbe commented Jul 1, 2021

same here: windows, python=3.6.8, numpy=1.19.5, Pillow=8.3.0

@seberg
Copy link

seberg commented Jul 1, 2021

Just to note, there is a small chance that some details changed in NumPy 1.19.x, but I doubt it matters. NumPy itself actually does not care whether you do return the correct dtype here, it is more of a hint at the moment. But, it is probably good habit to just return the requested dtype anyway.

garrettwrong added a commit to ComputationalCryoEM/ASPIRE-Python that referenced this issue Jul 1, 2021
@IceTDrinker
Copy link

IceTDrinker commented Jul 5, 2021

Any chance of a hotfix release ?

Edit : Every torchvision user using the ToTensor transform (i.e. all the vision people) will encounter the issue (and their build systems)

@janosh
Copy link

janosh commented Jul 6, 2021

Definitely needs a hot fix. This is all over the place.

@hugovk
Copy link
Member

hugovk commented Jul 6, 2021

There'll be an 8.3.1 soon, keep an eye on #5578. Thank you for your patience!

@radarhere
Copy link
Member

Pillow 8.3.1 has now been released with a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.