division for compound units not working properly
Bug #311499 reported by
John Salvatier
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-quantities |
Fix Released
|
Critical
|
Darren Dale |
Bug Description
These two should be the same, but they are not
>>>(5.2 * eV) / (400.0 * eV)
Quantity(
>>>(1.0 * J ) / ( 5.3 * J)
Quantity(
Changed in python-quantities: | |
assignee: | nobody → dsdale24 |
importance: | Undecided → Critical |
Changed in python-quantities: | |
milestone: | none → 0.1 |
Changed in python-quantities: | |
milestone: | none → 0.5.0 |
Changed in python-quantities: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
I think I fixed this:
in dimensionality.py I changed the __div__ function and got the correct behavior:
def __div__(self, other):
dimensions = copy.deepcopy( self._dimension s)
old. append( ou+'^%d' %od)
new. append( su+'^%d' %od)
else: units.append(su)
scaling, offset = _udunits. convert( old, new)
dimensions = self._dimensions - other._dimensions
compound = copy.deepcopy( self._compound) compound. items() :
compound[ k] -= v # changed this from += to -=
else:
compound[ k] = -v # changed from = v to = -v class__ (units, dimensions, **compound)
new._scaling = scaling
if not isinstance(other, Dimensionality):
scaling = self.scaling / float(other)
units = self.units
else:
units = []
old = []
new = []
for su, ou, od, in zip(self._units, other._units, other._dimensions):
if (su and ou) and (su != ou):
if ou and not su: units.append(ou)
old = '*'.join(old)
new = '*'.join(new)
for k, v in other._
if k in self._compound:
new = self.__
new._offset = offset
return new