Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 1 commit intomatplotlib:mainfrom3j14:fix-colors-from_list
Feb 1, 2025

Conversation

3j14
Copy link
Contributor

@3j143j14 commentedOct 31, 2024
edited
Loading

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

  • of typeSized (implements__len__),
  • not of typestr,
  • length 2.
  • first entry being a real number
  • second entry passing thematplotlib.colors.is_color_like test

Either 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.

Copy link

@github-actionsgithub-actionsbot left a 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 uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@3j14
Copy link
ContributorAuthor

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 userintends to do. For now this is solved by just looking at the first entry.

@tacaswelltacaswell added this to thev3.11.0 milestoneNov 1, 2024
@3j14
Copy link
ContributorAuthor

3j14 commentedNov 8, 2024

Concerning the pull request: Do you prefer if all commits are squashed into one, or will you take care of this when merging?

@3j14
Copy link
ContributorAuthor

3j14 commentedNov 8, 2024

Not sure how the failed checks are related to my changes. Are those just flaky checks?

@timhoffm
Copy link
Member

Sorry for the late reply.

Do you prefer if all commits are squashed into one, or will you take care of this when merging?

You are welcome to squash. If not, we'll do it on merge.

Not sure how the failed checks are related to my changes. Are those just flaky checks?

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.

@3j143j14force-pushed thefix-colors-from_list branch 2 times, most recently from15a693c to0fae9bdCompareDecember 9, 2024 10:16
@3j14
Copy link
ContributorAuthor

3j14 commentedDec 9, 2024

Thanks for your feedback! I added your remarks, squashed the commits and rebased onmain.
mypy failing appears to be unrelated.

timhoffm reacted with thumbs up emoji

@3j14
Copy link
ContributorAuthor

3j14 commentedDec 9, 2024

Thanks! Had to useassert_array_almost_equal for all checks – I assume there are some slight rounding errors caused by floating-point arithmetic. Similar tests also use theassert_array_almost_equal which was already imported.

timhoffm reacted with thumbs up emoji

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.Fixesmatplotlib#29042. Passing '(color, alpha)' tuples are nor correctly parsedas a list of colors.Check for range and monotony of values when unpacking (value, color)pairs.Implemented tests for different combinations of inputs.
@3j14
Copy link
ContributorAuthor

3j14 commentedDec 9, 2024

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 😅

@tacaswell
Copy link
Member

"power cycled" to get CI to re-run against current main (which should fix the mypy failures).

3j14 reacted with laugh emoji

@timhoffmtimhoffm merged commit46ea8f0 intomatplotlib:mainFeb 1, 2025
63 of 65 checks passed
@timhoffm
Copy link
Member

Thanks@3j14 and congratulations on your first contribution to Matplotlib! 🎉

3j14 reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@tacaswelltacaswelltacaswell approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[Bug]: colors.LinearSegmentedColormap.from_list fails when using a ("<color>", alpha) tuple
3 participants
@3j14@timhoffm@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp