Skip to content

Conversation

@alisterburt
Copy link

and expose cubehelix with Colormap("cubehelix", cmap_kwargs: dict[str, Any]) API

closes #19

…("cubehelix", cmap_kwargs: dict[str, Any]) API
@codecov
Copy link

codecov bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.57%. Comparing base (1697c07) to head (0915f0f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #134      +/-   ##
==========================================
- Coverage   96.24%   95.57%   -0.67%     
==========================================
  Files         168      169       +1     
  Lines        2181     2190       +9     
==========================================
- Hits         2099     2093       -6     
- Misses         82       97      +15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03
Copy link
Member

thanks @alisterburt! love the idea, would prefer to avoid a new registry though... and i think we should be able to avoid it. in the Colormap.__init__, if the value is a str, we can resolve it from the existing catalog:

cmap/src/cmap/_colormap.py

Lines 232 to 234 in 1697c07

if isinstance(value, str):
rev = value.endswith("_r")
info = self.catalog()[value[:-2] if rev else value]

and then info.data itself may be a callable (we don't need to separately track which ones are callable). So, you could perhaps just add another check in the __init__ there:

if cmap_kwargs and not callable(info.data):
    raise ShameOnYou
if isinstance(info.data, list):
    ...
else:
    data = partial(info.data, **cmap_kwargs) if callable(info.data) else info.data
    stops = _parse_colorstops(data)

thoughts?

@tlambert03
Copy link
Member

tlambert03 commented Jan 15, 2026

(and that shows that there are many more than just cubehelix)

In [5]: {x.name for x in Colormap.catalog().values() if callable(x.data)}
Out[5]: {'ocean', 'afmhot', 'gnuplot', 'heat', 'flag', 'prism', 'cubehelix', 'rainbow', 'fire', 'gnuplot2', 'grv'}

though, not all of those accept params... which raises the question: when should "bad" params be detected? I would think at init-time... but we might need to force the creation of a small lut to check it

@alisterburt
Copy link
Author

thanks for the fast turnaround on review - all makes sense, out and about today but will try to find some time in the coming days to get this over the line

@tlambert03
Copy link
Member

I'm also more than happy to do it if you were just opening the PR to be polite and don't care either way :)

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.

possibly add parameter parsing to string names, like cubehelix(1.5, 1.2, 1.0)

2 participants