Comment 1 for bug 311499

Revision history for this message
John Salvatier (jsalvatier) wrote :

I think I fixed this:

in dimensionality.py I changed the __div__ function and got the correct behavior:

   def __div__(self, other):
        if not isinstance(other, Dimensionality):
            scaling = self.scaling / float(other)
            units = self.units
            dimensions = copy.deepcopy(self._dimensions)
        else:
            units = []
            old = []
            new = []
            for su, ou, od, in zip(self._units, other._units, other._dimensions):
                if (su and ou) and (su != ou):
                    old.append(ou+'^%d'%od)
                    new.append(su+'^%d'%od)
                if ou and not su: units.append(ou)
                else: units.append(su)
            old = '*'.join(old)
            new = '*'.join(new)
            scaling, offset = _udunits.convert(old, new)
            dimensions = self._dimensions - other._dimensions
            compound = copy.deepcopy(self._compound)
            for k, v in other._compound.items():
                if k in self._compound:
                    compound[k] -= v # changed this from += to -=
                else:
                    compound[k] = -v # changed from = v to = -v
        new = self.__class__(units, dimensions, **compound)
        new._scaling = scaling
        new._offset = offset
        return new