Skip to content

fix: raise for an unknown colorspace in name2color and plot_spectral_locus - #248

Merged
petercorke merged 2 commits into
mainfrom
bug/name2color
Nov 23, 2026
Merged

petercorke merged 2 commits into
mainfrom
bug/name2color

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Fixes the two colorspace faults from the bug list.

  • name2color() caught ValueError around the whole conversion. That handler is meant for an unknown color name (Matplotlib raises ValueError for one), but the "unknown colorspace" error came through the same path, so name2color("red", "hsv") returned None and the message was never seen. The colorspace is now checked before the handler, so an unknown colorspace raises ValueError and an unknown name still returns None. A wildcard name returns the list of matching names as before.
  • plot_spectral_locus() tested colorspace in ("rg"), which is a substring test on a string, so "r", "g" and "" were taken as "rg". Any other value (for example "lab") fell through and raised UnboundLocalError, though the docstring promises ValueError. It now compares with == "rg" and raises ValueError for anything other than xy or rg.

The visible change is an unknown colorspace now raising where it returned None or plotted silently. I found no caller in the source, tests or book notebook that passes one. .. versionchanged:: 2.5.0 is on name2color.

Tests cover the unknown colorspace, an unknown name, upper-case colorspace names, a wildcard, and plot_spectral_locus with "lab", "r", "g" and "". mypy reports no issues and the full suite passes (2120 passed, 33 skipped).

AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.

🤖 Generated with Claude Code

petercorke and others added 2 commits November 23, 2026 15:48
…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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 7 complexity · 0 duplication

Metric Results
Complexity 7
Duplication 0

View in Codacy

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.

@petercorke
petercorke merged commit 2ec0f6d into main Nov 23, 2026
32 checks passed
@petercorke
petercorke deleted the bug/name2color branch November 23, 2026 06:14
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant