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: Fix unit example so that we can unpin numpy<2.1#29616

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
story645 merged 1 commit intomatplotlib:mainfromtimhoffm:fix-units
Feb 14, 2025

Conversation

timhoffm
Copy link
Member

Closes#28780.

The underlying problem is that operations on numpy scalars try to eagerly convert the other operand to an array. As a resultscalar = np .float64(2); scalar * radians would result in a numpy scalar. But we don't want that.

Instead we enforceradians.__rmul__(scalar) by giving the unit a higher__array_priority__. See alsonumpy/numpy#17650.

I haven't found any specific change notes on this in numpy 2.1. Interestingly, the full story is even more complex. Also for numpy<2.1radians.__rmul__(scalar) is not called, but there seems another mechanism through__array__ and__array_warp__ catching back in so that the result is again a TaggedValue. But I have not fully investigated why it worked previously. In fact, we want the solution here with going through__rmul__, and that works for all numpy versions.

Closesmatplotlib#28780.The underlying problem is that operations on numpy scalars try toeagerly convert the other operand to an array. As a result `scalar = np.float64(2); scalar * radians` would result in a numpy scalar. But we don't want that.Instead we enforce `radians.__rmul__(scalar)` by giving the unit ahigher`__array_priority__`. See also https://github.com/numpy/numpy/issues/17650.I haven't found any specific change notes on this in numpy 2.1.Interestingly, the full story is even more complex. Also for numpy<2.1`radians.__rmul__(scalar)` is not called, but there seems anothermechanism through __array__ and __array_warp__ catching back in so thatthe result is again a TaggedValue. But I have not fully investigated why it worked previously. In fact, we want the solution here with going through __rmul__, and that works for all numpy versions.`
@github-actionsgithub-actionsbot added the Documentation: examplesfiles in galleries/examples labelFeb 13, 2025
@timhoffmtimhoffm added this to thev3.10.0-doc milestoneFeb 13, 2025
@timhoffmtimhoffm changed the titleFIX: Fix unit example so that we can unpin numpy>2.1FIX: Fix unit example so that we can unpin numpy<2.1Feb 13, 2025
Copy link
Member

@story645story645 left a comment
edited
Loading

Choose a reason for hiding this comment

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

but also will follow up on discussion in issue about this example

@story645story645 merged commit3fa730d intomatplotlib:mainFeb 14, 2025
40 checks passed
@lumberbot-appLumberbot (App)
Copy link

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.10.xgit pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 3fa730d807f823baa27177a1a499cd7e293537fb
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #29616: FIX: Fix unit example so that we can unpin numpy<2.1'
  1. Push to a named branch:
git push YOURFORK v3.10.x:auto-backport-of-pr-29616-on-v3.10.x
  1. Create a PR against branch v3.10.x, I would have named this PR:

"Backport PR#29616 on branch v3.10.x (FIX: Fix unit example so that we can unpin numpy<2.1)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove theStill Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free tosuggest an improvement.

@lumberbot-appLumberbot (App)
Copy link

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.10.0-docgit pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 3fa730d807f823baa27177a1a499cd7e293537fb
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #29616: FIX: Fix unit example so that we can unpin numpy<2.1'
  1. Push to a named branch:
git push YOURFORK v3.10.0-doc:auto-backport-of-pr-29616-on-v3.10.0-doc
  1. Create a PR against branch v3.10.0-doc, I would have named this PR:

"Backport PR#29616 on branch v3.10.0-doc (FIX: Fix unit example so that we can unpin numpy<2.1)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove theStill Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free tosuggest an improvement.

@timhoffmtimhoffm deleted the fix-units branchFebruary 14, 2025 05:44
QuLogic pushed a commit to QuLogic/matplotlib that referenced this pull requestFeb 14, 2025
@QuLogic
Copy link
Member

Don't see any point of backporting to the doc branch if 3.10.1 is imminent.

@QuLogicQuLogic modified the milestones:v3.10.0-doc,v3.10.1Feb 14, 2025
timhoffm added a commit that referenced this pull requestFeb 14, 2025
…3.10.xBackport PR#29616 on branch v3.10.x (FIX: Fix unit example so that we can unpin numpy<2.1)
@timhoffm
Copy link
MemberAuthor

It's not urgent but somehow these changes should propagate to the doc branch. How does it work? Is doc reset to 3.10.x when that is released or is 3.10.x merged into doc?

@QuLogic
Copy link
Member

It's merged together before a release, and v3.10.1-doc starts fresh after v3.10.1

timhoffm reacted with thumbs up emoji

@ksundenksunden mentioned this pull requestMar 3, 2025
5 tasks
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@story645story645story645 approved these changes

Assignees
No one assigned
Labels
Documentation: examplesfiles in galleries/examples
Projects
None yet
Milestone
v3.10.1
Development

Successfully merging this pull request may close these issues.

Doc build fails with numpy>=2.1.0
3 participants
@timhoffm@QuLogic@story645

[8]ページ先頭

©2009-2025 Movatter.jp