astropy/astropy — pull request #672 by mdboom (2013-01-24 17:19:03+00:00)
Title: Unit conversion on quantities mishandles long values

I came across the inconsistency below using the units module. Unfortunately I don't have time to explore what's going on...

This works fine:

```python
>>> import astropy.units as u
>>> sigma = (100 * u.M_sun / u.pc**2)
>>> print sigma.to(u.M_p / u.cm**2)
1.24898660319e+22 M_p / (cm2)
```

but going the opposite way doesn't work:

```python
>>> sigma = 10**21 * u.M_p / u.cm**2
>>> sigma.to(u.M_sun / u.pc**2)

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 sigma.to(u.M_sun / u.pc**2)

/usr/local/lib/python2.7/dist-packages/astropy/units/quantity.pyc in to(self, unit, equivalencies)
84 directly convertible. See :ref:`unit_equivalencies`.
85 """
---> 86 new_val = self.unit.to(unit, self.value, equivalencies=equivalencies)
87 new_unit = Unit(unit)
88 return Quantity(new_val, new_unit)

/usr/local/lib/python2.7/dist-packages/astropy/units/core.pyc in to(self, other, value, equivalencies)
368 other = Unit(other)
369 return self.get_converter(
--> 370 other, equivalencies=equivalencies)(value)
371
372 def in_units(self, other, value=1.0, equivalencies=[]):

/usr/local/lib/python2.7/dist-packages/astropy/units/core.pyc in (val)
336 return self._apply_equivalences(
337 self, other, equivalencies)
--> 338 return lambda val: scale * _condition_arg(val)
339
340 def to(self, other, value=1.0, equivalencies=[]):

/usr/local/lib/python2.7/dist-packages/astropy/units/core.pyc in _condition_arg(value)
1163 except ValueError:
1164 raise ValueError(
-> 1165 "Value not scalar compatible or convertable into a float or "
1166 "integer array")

ValueError: Value not scalar compatible or convertable into a float or integer array
```