BUG Raise exception for invalid input#2632
BUG Raise exception for invalid input#2632luispedro wants to merge 2 commits intomatplotlib:masterfrom
Conversation
Arrays of non-uint8 types were assumed to be in 0..1 range. When this was not true and integer values were used, only the low-order bits were used, resulting in a mangled image. Now, an explicit exception is raised. Closes issue matplotlib#2499
lib/matplotlib/cm.py
Outdated
There was a problem hiding this comment.
The test failure is a pep8 violation on this line.
|
Sorry, I didn't look at this change closely enough last night. The docstring on |
|
I don't think we want to be doing this 0-1 check at all. What would make sense is to raise an exception if the input is integer type but not uint8, since uint8 is the only supported integer type. This check is fast to do, and entirely consistent with the logic of the method; it would require a change to the docstring to remove the statement that dtype is not checked. It would have to be clear that the integer-is-uint8 check is done only in the rgb or rgba case. In the mappable array case, any integer type is allowed, triggering direct indexing into the colormap LUT. |
|
Right now matplotlib correctly displays binary images. As a user, I'd prefer if it kept that functionality. |
|
@luispedro Would you elaborate, please, on your last comment? I don't understand what it means with respect to this PR, and my preceding recommendation. What do you mean by "displays binary images"? With what kinds of input array? |
|
I meant boolean images. For example: I feel that at least |
|
Included in #6122. |
Arrays of non-uint8 types were assumed to be in 0..1 range.
When this was not true and integer values were used, only the low-order
bits were used, resulting in a mangled image. Now, an explicit exception
is raised.
Closes issue #2499