astropy/astropy — pull request #2069 by lgarrison (2014-02-10 04:06:58+00:00)
Title: Units power rounding

I found the following strange occurrence in the units package, where a conversion works when using quantity ```tH.cgs```, but not when using the unadorned quantity ```tH```:
```
m = 1e9 * u.Msun
tH = 1./(70. * u.km/u.s/u.Mpc)
vc = 200 * u.km/u.s

x = (c.G**2 * m**2 * tH.cgs)**(1./3) / vc # Units of length
x.to('pc') # Succeeds

x = (c.G**2 * m**2 * tH)**(1./3) / vc # Units of length
x.to('pc') # Fails with a UnitsError
```
The cause is that ```x.cgs.unit.powers[0]``` is ```1.0``` in the first case, and ```1.0000000000000002``` in the second.

It seemed to me that this could be dealt with using ```np.allclose``` in the ```_to()``` function of ```core.py``` instead of a strict equality, but I'd like to know if others think this is an acceptable solution. I've written a regression test for the issue as well.

Lehman