Commit 2c087c1
committed
FIX: Fix unit example so that we can unpin numpy>2.1
Closes matplotlib#28780.
The underlying problem is that operations on numpy scalars try to
eagerly 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 a
higher
`__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 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.
`1 parent 2d5e503 commit 2c087c1
File tree
3 files changed
+7
-2
lines changed- .circleci
- galleries/examples/units
3 files changed
+7
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
196 | 201 | | |
197 | 202 | | |
198 | 203 | | |
| |||
0 commit comments