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

Skip to content

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

Merged
merged 2 commits into from
Mar 23, 2022

Conversation

oscargus
Copy link
Member

@oscargus oscargus commented Mar 18, 2022

PR Summary

Closes #22662

The error message when supplying an empty string for color was a bit confusing:

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.")

Now a dedicated version is used for the empty string:

raise ValueError("Using an empty string for color is not "
                 "supported. Use 'none' if you do not want to "
                 "set a color.")

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

Comment on lines 365 to 372
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.")
Copy link
Member

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

Suggested change
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")

@oscargus oscargus force-pushed the emptycolorerrormessage branch from 355edb7 to 6a7358a Compare March 22, 2022 08:14
@oscargus oscargus force-pushed the emptycolorerrormessage branch from 6a7358a to e30cd8e Compare March 22, 2022 08:15
@oscargus oscargus changed the title Improve error message for empty string color Improve error message for incorrect color string Mar 22, 2022
@tacaswell tacaswell added this to the v3.6.0 milestone Mar 23, 2022
Copy link
Member

@tacaswell tacaswell left a 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.

@tacaswell tacaswell merged commit 6310073 into matplotlib:main Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leave color parameter empty should be fine[ENH]:
4 participants