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

test_png is failing #20560

Closed
jklymak opened this issue Jul 1, 2021 · 1 comment · Fixed by #20565
Closed

test_png is failing #20560

jklymak opened this issue Jul 1, 2021 · 1 comment · Fixed by #20565
Milestone

Comments

@jklymak
Copy link
Member

jklymak commented Jul 1, 2021

lib/matplotlib/tests/test_png.py:19: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
lib/matplotlib/pyplot.py:2378: in imread
    return matplotlib.image.imread(fname, format)
lib/matplotlib/image.py:1544: in imread
    if isinstance(image, PIL.PngImagePlugin.PngImageFile) else
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

pil_png = <PIL.PngImagePlugin.PngImageFile image mode=1 size=32x32 at 0x7F4A53D83910>

    def _pil_png_to_float_array(pil_png):
        """Convert a PIL `PNGImageFile` to a 0-1 float array."""
        # Unlike pil_to_array this converts to 0-1 float32s for backcompat with the
        # old libpng-based loader.
        # The supported rawmodes are from PIL.PngImagePlugin._MODES.  When
        # mode == "RGB(A)", the 16-bit raw data has already been coarsened to 8-bit
        # by Pillow.
        mode = pil_png.mode
        rawmode = pil_png.png.im_rawmode
        if rawmode == "1":  # Grayscale.
>           return np.asarray(pil_png, np.float32)
E           TypeError: __array__() takes 1 positional argument but 2 were given
@ianthomas23
Copy link
Member

This has been reported in pillow as python-pillow/Pillow#5571.

As a temporary workaround, you can separate the conversion to numpy array and changing dtype, i.e. from

return np.asarray(pil_png, np.float32)

to

return np.asarray(pil_png).astype(np.float32)

@tacaswell tacaswell added this to the v3.4.3 milestone Jul 1, 2021
@jklymak jklymak mentioned this issue Jul 2, 2021
7 tasks
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.

3 participants