Skip to content

BUG: DataFrame.plot raises ValueError when color name is specified by multiple characters #10387

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 1 commit into from
Jul 1, 2015

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Jun 18, 2015

Derived from #9894. Passing color name with multiple characters results in ValueError. Below is the bahavior of current master.

# OK
df = pd.DataFrame(np.random.randn(3, 3))
df[0].plot(color='green')
# single green line

# OK
df.plot(color=['green'])
# triple green lines

# NG
df.plot(color='green')
# ValueError: to_rgba: Invalid rgba arg "e"
# -> This should be triple green lines

If passed str can be parsed as both single color and color cycle, following error will be raised.

  • "'green' can be parsed as both single color and color cycle. Specify each color using a list like ['green'] or ['g', 'r', 'e', 'e', 'n']"

Currently, there is no color name which can meet above condition (thus cannot tested).

@sinhrks
Copy link
Member Author

sinhrks commented Jun 18, 2015

@jorisvandenbossche
Copy link
Member

Why is the third case not OK? I would only rasie the error if the length is correct (corresponds with the number of columns, as only then it is ambiguous?)

@sinhrks sinhrks added this to the 0.17.0 milestone Jun 18, 2015
@sinhrks
Copy link
Member Author

sinhrks commented Jun 18, 2015

Ah, I meant NG(raise error) in current master. The fix allows to draw 3rd case with 3 lines in green.

I would only rasie the error if the length is correct (corresponds with the number of columns, as only then it is ambiguous?)

Currently, the logic only checks whether the input can be parsed as both single color and color cycle, without comparing input length and the number of columns. Because color='rg' for 10 columns DataFrame is valid as color cycle.

@jorisvandenbossche
Copy link
Member

ah, yes :-)

Yes, for the length, you can ignore my comment, as now if the length is shorter it is regarded as a cycle that gets repeated, I see now

# ``colors`` is regarded as color cycle.
# mpl will raise error any of them is invalid
pass
print(colors, num_colors)
Copy link
Member

Choose a reason for hiding this comment

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

leftover

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! 😓

@sinhrks sinhrks force-pushed the plot_color_str branch 3 times, most recently from 8154b1a to 6d8a192 Compare June 19, 2015 14:44
@sinhrks
Copy link
Member Author

sinhrks commented Jun 22, 2015

@TomAugspurger Can you check this when you have a time?

@sinhrks
Copy link
Member Author

sinhrks commented Jul 1, 2015

@TomAugspurger @jorisvandenbossche Looks OK? Let me merge this if there is no objection until this weekend.

@jorisvandenbossche
Copy link
Member

Looks ok to me!

@TomAugspurger
Copy link
Contributor

👍

jorisvandenbossche added a commit that referenced this pull request Jul 1, 2015
BUG: DataFrame.plot raises ValueError when color name is specified by multiple characters
@jorisvandenbossche jorisvandenbossche merged commit c4c5d44 into pandas-dev:master Jul 1, 2015
@jorisvandenbossche
Copy link
Member

Voila!

@sinhrks
Copy link
Member Author

sinhrks commented Jul 1, 2015

Thanks. Will back to #9894.

@sinhrks sinhrks deleted the plot_color_str branch July 1, 2015 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants