-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix example's BasicUnit array conversion. #19535
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
The remaining failure is:
I am using NumPy 1.18.1/1.18.5. It appears to have fixed itself in 1.19.0. @dstansby |
It seems that our attempts to use a minimum version of numpy is getting foiled on cricle and we are running the minimum version docs build with np 1.20 🤦 . |
Good catch; hopefully this should work to fix that. |
dc89aba
to
64a66b0
Compare
64a66b0
to
46ad1c9
Compare
A unit is a scalar, not a length-1 array. Though `BasicUnit` implements `__rmul__`, if multiplying by an array, the NumPy implementation will call `__array__` instead. If the LHS is an array, everything is fine, but if the LHS is a scalar, the previous code would incorrectly cause it to be upcast to a 1D array. When `__getitem__` was added in matplotlib#19415, `np.atleast_1d` started iterating each (now 1D, not scalar) `TaggedValue`, seeing it was length 1, and made the x/y arrays into (N, 1) instead of (N,).
On older versions (1.18), this breaks things, so must be skipped.
46ad1c9
to
3488dc7
Compare
I looked to see what this example does, but it doesn't do anything except register itself? |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
It's imported by all the other examples in this directory. |
With other backports done, I hope this will work now. @meeseeksdev backport to v3.4.x |
…535-on-v3.4.x Backport PR #19535 on branch v3.4.x (Fix example's BasicUnit array conversion.)
PR Summary
The unit examples are broken in NumPy < 1.20. This fixes a bug that was exposed by #19415
, but does not fix the examples fully.radian_demo
is fixed by this change, butellipse_with_units
is still broken. I do not understand the NumPy subclassing methods enough to fix it short of reverting #19415..A unit is a scalar, not a length-1 array. Though
BasicUnit
implements__rmul__
, if multiplying by an array, the NumPy implementation will call__array__
instead. If the LHS is an array, everything is fine, but if the LHS is a scalar, the previous code would incorrectly cause it to be upcast to a 1D array. When__getitem__
was added in #19415,np.atleast_1d
started iterating each (now 1D, not scalar)TaggedValue
, seeing it was length 1, and made the x/y arrays into (N, 1) instead of (N,).PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).