-
Notifications
You must be signed in to change notification settings - Fork 18
Lazy loading colormaps #343
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
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
|
hmm this test that is failing is passing locally.. strange |
1c6a465 to
6e3278d
Compare
b187ee4 to
f2dae18
Compare
| # by overriding matplotlib's behavior | ||
| for name in tuple(self._cmaps.keys()): | ||
| self.register(self._cmaps[name], name=name) | ||
| super().__init__({k.lower(): v for k, v in kwargs.items()}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why switch to k.lower() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We perform a lower command internally later when the colormap is registered.
| # such that ultraplot knows what these objects are. We piggy back on the registering mechanism | ||
| # by overriding matplotlib's behavior | ||
| for name in tuple(self._cmaps.keys()): | ||
| self.register(self._cmaps[name], name=name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we are no longer using the register method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch. We do need it as we override the ColormapRegistery. Moved the lazy loading from file to a private function to make this distinction clearer and still rely on register
ultraplot/colors.py
Outdated
| raise ValueError( | ||
| f"Invalid colormap type {type!r} for key {key!r} in file {path!r}. " | ||
| "Expected 'continuous' or 'discrete'." | ||
| ) | ||
|
|
||
| if cmap: | ||
| if is_default and cmap.name.lower() in CMAPS_CYCLIC: | ||
| cmap.set_cyclic(True) | ||
| self._cmaps[key] = cmap | ||
| value = cmap | ||
| else: # failed to load | ||
| # remove from registry to avoid trying again | ||
| del self._cmaps[key] | ||
| raise KeyError(f"Failed to load colormap {key!r} from {path!r}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous code warned on failures at least according to the keyword. This code appears to raise an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change it back to a warn.
This PR changes the colormap loading to lazy loading -- effectively reducing the import time from
0.38sto0.00082sfor the colormaps.