astropy/astropy — pull request #1714 by mdboom (2013-10-31 17:36:49+00:00)
Title: Quantity to Angle issue / Fix comparing irreducible units by identity

This is a replacement for #1703. I had tried to do it as a PR against @jwoillez's branch, but it required a rebase against master to get some recent bugfixes there. Sorry to hijack your PR, @jwoillez.

In addition to the work in #1703, this restores the behavior that the "is" operator is used for comparing irreducible (base) units. It turns out that using `Quantity` often creates `CompositeUnit`s unnecessarily -- creating composite units that are nothing more than an unnecessary shell around a single irreducible unit. This breaks the ability to check a unit for an exact match with the `is` operator, which is required since base units should not be considered the same if only their names are -- i.e. it should not be possible for a user to redefine a base SI unit.

This also has performance advantages, since the creation and subsequent simplification of composite units is a major performance bottleneck.

Before:

```
In [2]: timeit.timeit("1.0*u.m", "from astropy import units as u", number=100000)
Out[2]: 8.104776859283447
```

After:

```
In [2]: timeit.timeit("1.0*u.m", "from astropy import units as u", number=100000)
Out[2]: 5.921447992324829
```