Skip to content

Commit 47ae6db

Browse files
committed
Merge pull request #8 from astrofrog/quantity/allow-arrays-fix
Make array * unit return a Quantity containing an array, not an array of quantites
2 parents be7045e + 88deb72 commit 47ae6db

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎astropy/units/core.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class UnitBase(object):
5151
_registry = []
5252
_namespace = {}
5353

54+
# Make sure that __rmul__ of units gets called over the __mul__ of Numpy
55+
# arrays to avoid element-wise multiplication.
56+
__array_priority__ = 1000
57+
5458
def __deepcopy__(self, memo):
5559
# This may look odd, but the units conversion will be very
5660
# broken after deep-copying if we don't guarantee that a given

‎astropy/units/tests/test_quantity.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ def test_arrays():
314314
assert_array_equal((qsec - 2).value, (np.arange(10) + 2))
315315

316316
#should create by unit multiplication, too
317-
#qsec2 = np.arange(10) * u.second # TODO: replace the next line with this once we figure out how to make numpy * unit work right
318-
qsec2 = u.Quantity(np.arange(10), u.second)
317+
qsec2 = np.arange(10) * u.second
319318
qsec3 = u.second * np.arange(10)
320319

321320
assert np.all(qsec == qsec2)

0 commit comments

Comments
 (0)