-
Notifications
You must be signed in to change notification settings - Fork 18
fix late binding and proper reversal for funcs #296
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 late binding and proper reversal for funcs #296
Conversation
f0342a3 to
6f56ae5
Compare
6f56ae5 to
f23710b
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ultraplot/colors.py
Outdated
| # Try mirroring the non-lowered key | ||
| if reverse: | ||
| original_key = original_key.strip("_r") | ||
| original_key = original_key.rstrip("_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.
This method removes any of the characters in _r, not _r if the string ends with _r. I think you may want something like original_key.rsplit("_r", maxsplit=1)[0]
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.
You are correct, but then we should replace all strip functions by a split you suggest. My edit here merely replaces it with a more appropriate function. I think the original strip is wrong as it also deletes leading "_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.
Right we should do that fix. We'll need another PR
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 can also include it in here, although I think this issue will not be a major things as the _r is added by ultraplot. If the colormap ends with _r it will be listed as {cmapnameendingwith_r}_r which should then split fine I think.
|
We can go ahead and merge this I guess @beckermr? |
|
Didn't you want to fix the string _r thing here too? |
|
Ah ok that wasn't entirely clear. Will do that now |
|
done ;-)! |

A secondary issue came up in #294 where a callable is not properly inverse.
This PR fixes a bug in the reversal of colormap segment data where callable segments were incorrectly captured due to Python’s late binding behavior in closures. Specifically, lambdas inside the dictionary comprehension referenced the loop variable data, which caused all callables to use the last data value. This is resolved by binding data as a default argument in the lambda. Explicit segment lists are unaffected and still reversed correctly.