Repository navigation
feat: add color_names and remove the wildcard from name2color - #249
Merged
Merged
Conversation
…locus
name2color caught ValueError around the whole conversion, so an unknown
colorspace returned None, the same as an unknown color name.
plot_spectral_locus tested colorspace in ("rg"), a substring test, so "r",
"g" and "" were accepted as rg, and any other value raised
UnboundLocalError instead of the ValueError its docstring promises.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
name2color returned a color value, a list of names (for a name containing ., ? or *) or None, which made its return type awkward for callers. color_names(pattern) lists the Matplotlib color names, all of them or those whose whole name matches a Python regular expression. name2color now raises ValueError for a name with a wildcard, pointing to color_names. The chap10 notebook uses color_names for the coral example. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 16 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
color_names()and removes the wildcard feature fromname2color().name2color()returned a color value, a list of names (when the name contained.,?or*) orNone. That made its return type awkward: three callers needed a# type: ignoreor anAny. The wildcard test was also unreliable. A name was treated as a pattern only if it contained one of three characters, so^redor[ab]returnedNone, and the pattern was matched withre.match, which only anchors the start.color_names(pattern=None)returns every Matplotlib color name, or those whose whole name matches a Python regular expression (re.fullmatch). The docstring states, in an.. important::block, that this is a Python regular expression and not a shell wildcard:.*coral.*, not*coral*. A pattern that is not a valid regular expression raisesValueErrorwhose message says*and?are not shell wildcards.name2color()raisesValueErrorfor a name with a wildcard, and the message namescolor_names(). Its return type is nowndarray | None. Both changes have.. versionchanged:: 2.5.0.color2name()docstring said a color name may contain a wildcard such as"?burnt", which as a regular expression is an error. That line is removed.name2color(".*coral.*")becomescolor_names(".*coral.*")intests/RVC/chap10.ipynb. This is a change to the printed book code, so it needs an errata entry (the maintainer is adding one).Stacked on the colorspace fix (PR for
bug/name2color), which has to merge first. Tests cover listing all names, patterns, whole-name matching, alternatives, no match, every name being accepted byname2color, and the two error messages. mypy reports no issues and the full suite passes (2127 passed, 33 skipped).AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.
🤖 Generated with Claude Code