Skip to content
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

feat: expose catalog as Colormap classmethod #22

Merged
merged 9 commits into from
Sep 6, 2023
Merged

Conversation

tlambert03
Copy link
Owner

@tlambert03 tlambert03 commented Sep 6, 2023

This PR is working towards making it easier to query the available colormap keys. It adds a couple of public conveniences:

from cmap import Colormap

# access global catalog
catalog = Colormap.catalog()

# various ways to query for available keys:


def unique_keys(
    self, prefer_short_names: bool = True, normalized_names: bool = False
) -> set[str]:
    """Return names that refer to unique colormap data.

    Parameters
    ----------
    prefer_short_names : bool, optional
        If True (default), short names (without the namespace prefix) will be
        preferred over fully qualified names. In cases where the same short name
        is used in multiple namespaces, they will *all* be referred to by their
        fully qualified (namespaced) name.
    normalized_names : bool, optional
        If True, return the normalized names of the colormaps.  If False
        (default), return the original names of the colormaps (which may include
        spaces and/or capital letters).
    """

def short_keys(self) -> set[str]:
    """Return a set of available short colormap names, without namespace."""

def namespaced_keys(self) -> set[str]:
    """Return a set of available short colormap names, with namespace."""

def resolve(self, name: str) -> str:
    """Return the fully qualified, normalized name of a colormap or alias."""

@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Merging #22 (0d6e074) into main (c089822) will increase coverage by 0.02%.
The diff coverage is 98.91%.

@@            Coverage Diff             @@
##             main      #22      +/-   ##
==========================================
+ Coverage   96.88%   96.90%   +0.02%     
==========================================
  Files         151      151              
  Lines        1796     1842      +46     
==========================================
+ Hits         1740     1785      +45     
- Misses         56       57       +1     
Files Changed Coverage Δ
src/cmap/_external.py 94.91% <ø> (ø)
src/cmap/_catalog.py 99.19% <98.75%> (-0.81%) ⬇️
src/cmap/__init__.py 100.00% <100.00%> (ø)
src/cmap/_colormap.py 87.98% <100.00%> (+0.19%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tlambert03 tlambert03 enabled auto-merge (squash) September 6, 2023 20:12
@tlambert03 tlambert03 merged commit 79991a6 into main Sep 6, 2023
17 checks passed
@tlambert03 tlambert03 deleted the update-catalog branch September 6, 2023 20:13
@tlambert03 tlambert03 added the enhancement New feature or request label Sep 6, 2023
@tlambert03 tlambert03 changed the title refactor: expose catalog as Colormap classmethod feat: expose catalog as Colormap classmethod Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant