Skip to content

Commit cb09f6d

Browse files
committed
determine dtype in scale_other_units
1 parent 412cdf9 commit cb09f6d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

quantities/quantity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def g(self, other, *args):
5959
if not isinstance(other, Quantity):
6060
other = other.view(type=Quantity)
6161
if other._dimensionality != self._dimensionality:
62-
other = other.rescale(self.units)
62+
other = other.rescale(self.units, dtype=np.result_type(self.dtype, other.dtype))
6363
return f(self, other, *args)
6464
return g
6565

quantities/tests/test_arithmetic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ def test_in_place_subtraction(self):
358358
self.assertRaises(ValueError, op.isub, [1, 2, 3]*pq.m, pq.J)
359359
self.assertRaises(ValueError, op.isub, [1, 2, 3]*pq.m, 5*pq.J)
360360

361+
def test_division(self):
362+
molar = pq.UnitQuantity('M', 1e3 * pq.mole/pq.m**3, u_symbol='M')
363+
for subtr in [1, 1.0]:
364+
q = 1*molar/(1000*pq.mole/pq.m**3)
365+
self.assertQuantityEqual((q - subtr).simplified, 0)
366+
361367
def test_powering(self):
362368
# test raising a quantity to a power
363369
self.assertQuantityEqual((5.5 * pq.cm)**5, (5.5**5) * (pq.cm**5))

0 commit comments

Comments
 (0)