Skip to content

Commit 4cca449

Browse files
committed
Fix example's BasicUnit array conversion.
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,).
1 parent 5ad390d commit 4cca449

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

examples/units/basic_units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __array_wrap__(self, array, context):
218218
return TaggedValue(array, self)
219219

220220
def __array__(self, t=None, context=None):
221-
ret = np.array([1])
221+
ret = np.array(1)
222222
if t is not None:
223223
return ret.astype(t)
224224
else:

0 commit comments

Comments
 (0)