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

FIX: Enable str transformations to Color/Interval scales #3688

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MaozGelbart
Copy link
Contributor

Prior to this PR, strings such as "log", "sqrt", etc. (.scale "magic args") are invalid inputs to Color/Interval variables' scales (#2869). It is possible to define a Continuous(trans="log") scale and achieve continuous transformation functionality to these properties. So the following lines are equivalent but the former is currently erroneous:

so.Plot(tips, "total_bill", "tip", color="total_bill").add(so.Dots()).scale(color="log")
so.Plot(tips, "total_bill", "tip", color="total_bill").add(so.Dots()).scale(color=so.Continuous(trans="log"))

This PR adds str transformations support directly to Color/Interval properties. It is resolved after property-specific arguments (i.e. .scale(color="log") will look for "log" colormap first and will apply "log" transformation only if there's no "log" colormap registered).

Fixes #2869 .

# Prioritize actual colormaps, e.g. if a colormap named "pow" exists
if is_registered_colormap(arg):
return Continuous(arg)
elif any(arg.startswith(k) for k in self._TRANS_ARGS):
Copy link
Contributor

@thuiop thuiop May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be startswith or == ? With the current code, passing "logfoo" for instance would redirect it to trans; is that what we want ? Same comment for other parts where this happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment. I didn't want to change this since it is similar to how it's performed elsewhere in this module and in other parts of the codebase (_core.scales for example). I reckon the original intention in using startswith was to support "log2", "symlog100", etc. Anyway, passing "logfoo" would fail even prior to this PR (with ValueError: 'logfoo' is not a valid palette name).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, the prefix checks allow the "string parameterized scale transform" spelling but maybe that needs better error checking.

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.

Color scales do not accept name of transform as magic arg
3 participants