-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve error message for incorrect color string #22665
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
Conversation
lib/matplotlib/colors.py
Outdated
if len(c): | ||
raise ValueError("Using a string of single character colors as " | ||
"a color sequence is not supported. The colors " | ||
"can be passed as an explicit list instead.") | ||
else: | ||
raise ValueError("Using an empty string for color is not " | ||
"supported. Use 'none' if you do not want any " | ||
"color.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"string of single characters" was deprecated in 3.2 and removed in 3.4 (#18069). IMHO we don't need to bother users with that anymore - It's even more likely nowadays that they have just made a typo like 'yellwo'.
We should at least change the first message to raise ValueError(f"{c!r} is not a valid color value")
I even argue that the empty distinction is not necessary. We don't do this in other parts of the code either (c.f. plt.plot([0], color='')
. I'd just go for
if len(c): | |
raise ValueError("Using a string of single character colors as " | |
"a color sequence is not supported. The colors " | |
"can be passed as an explicit list instead.") | |
else: | |
raise ValueError("Using an empty string for color is not " | |
"supported. Use 'none' if you do not want any " | |
"color.") | |
raise ValueError(f"{c!r} is not a valid color value") |
355edb7
to
6a7358a
Compare
6a7358a
to
e30cd8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone can merge on CI green.
PR Summary
Closes #22662
The error message when supplying an empty string for color was a bit confusing:
Now a dedicated version is used for the empty string:
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).