-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: Checks for (value, color) tuples in LinearSegmentedColormap.from_list #29052
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
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
I must say, the code got a whole lot more complicated. If you think it became too unreadable, I'd be happy to discuss how we can improve it. But I felt like these checks were important to catch user errors and give meaningful feedback. The problem is that the inputs are ambiguous, and it is not possible to tell what the user intends to do. For now this is solved by just looking at the first entry. |
eb8a638
to
bb550e1
Compare
Concerning the pull request: Do you prefer if all commits are squashed into one, or will you take care of this when merging? |
Not sure how the failed checks are related to my changes. Are those just flaky checks? |
Sorry for the late reply.
You are welcome to squash. If not, we'll do it on merge.
The CI runs have been deleted meanwhile. I assume the failures were unrelated. We had a couple of failing tests recently. Please try to rebase, that should likely fix it. |
15a693c
to
0fae9bd
Compare
Thanks for your feedback! I added your remarks, squashed the commits and rebased on |
0fae9bd
to
eb02204
Compare
Thanks! Had to use |
Assume that the 'colors' argument is always a list of colors. If 'to_rgba_array' fails, attempt to unpack the values as a list of '(color, value)' tuples. Fixes matplotlib#29042. Passing '(color, alpha)' tuples are nor correctly parsed as a list of colors. Check for range and monotony of values when unpacking (value, color) pairs. Implemented tests for different combinations of inputs.
eb02204
to
d9b8020
Compare
The last commit had some old unused parameter in one test case, causing pytest to complain about a missing fixture. Sorry for the confusion. I amended that commit already but forgot to push 😅 |
"power cycled" to get CI to re-run against current main (which should fix the mypy failures). |
Thanks @3j14 and congratulations on your first contribution to Matplotlib! 🎉 |
PR summary
Fixes #29042.
By default, a list of colors is assumed. Only if the conversion to rgba values fails, check for (value, color) pairs.
The check of the first entry in colors in preserved to raise more meaningful error messages.
For the first item to be interpreted as a valid (value, color) tuple, it has to be
Sized
(implements__len__
),str
,matplotlib.colors.is_color_like
testEither way, errors are returned if not all entries are (value, color) pairs or if any invalid colors are encountered.
Implemented tests for different combinations of inputs.