astropy/astropy — pull request #1438 by mdboom (2013-09-20 22:01:25+00:00)
Title: Unit.decompose into compound units broken

As reported by @adrn on the astropy-dev mailing list

Prior to this commit:
https://github.com/astropy/astropy/commit/a81d6af977920c8a8044d04c19f928a0556e7ab6

I was able to decompose to any arbitrary set of units, even
CompositeUnits, e.g.:

from astropy.constants import G
G.decompose([u.kg, u.km, u.Unit("15 s")])

But this line was changed in the above commit:

(1452)
- new_parts.sort(key=lambda x: x[1], reverse=True)
+ new_parts.sort(key=lambda x: (x[1], x[0].name), reverse=True)

And now, because CompositeUnit has no .name, it fails. Was this intentional?

It's very handy for me to decompose constants to arbitrary sets of
units. I work a lot with dynamical simulations which are often done in
scaled units which then have to be converted back and forth to
physical values.

Thanks!