Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adds check that rgb sequence is of length 3 #3092

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

Merged
merged 3 commits into from
Jun 2, 2014

Conversation

GregoryAshton
Copy link
Contributor

Fixes issue in #3079 . I ran the tests
and nothing breaks but I am unsure if it will break something else.

if [x for x in (r, g, b) if (float(x) < 0) or (x > 1)]:
if len(arg) == 3:
r, g, b = arg
if [x for x in (r, g, b) if (float(x) < 0) or (x > 1)]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better as if any(float(x) < 0 or float(x) > 0 for x in arg): (and might as well change the rest in this function too).

@@ -349,8 +349,7 @@ def to_rgba(self, arg, alpha=None):
try:
if not cbook.is_string_like(arg) and cbook.iterable(arg):
if len(arg) == 4:
if [x for x in arg if (float(x) < 0) or (x > 1)]:
# This will raise TypeError if x is not a number.
if any(float(x) < 0. or float(x) > 1. for x in arg):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second float conversion is unnecessary, as are both decimal points. The only purpose of the float conversion is to trigger an error if, for example,

arg = np.array(['a', 'b', 'c'])

Contrary to the comment, it raises a ValueError; but that serves the purpose just as well.

@tacaswell tacaswell added this to the v1.4.0 milestone May 29, 2014
tacaswell added a commit that referenced this pull request Jun 2, 2014
Adds check that rgb sequence is of length 3
@tacaswell tacaswell merged commit ea8fa7b into matplotlib:master Jun 2, 2014
@GregoryAshton GregoryAshton deleted the fix-issue-3079 branch July 26, 2014 15:38
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

Successfully merging this pull request may close these issues.

4 participants