BUG: DataFrame.plot raises ValueError when color name is specified by multiple characters by sinhrks · Pull Request #10387 · pandas-dev/pandas (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation12 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
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).
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?)
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.
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) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 😓
jorisvandenbossche added a commit that referenced this pull request
BUG: DataFrame.plot raises ValueError when color name is specified by multiple characters
Thanks. Will back to #9894.