astropy/astropy — pull request #706 by astrofrog (2013-01-30 14:46:36+00:00)
Title: Cannot access items from Quantity array

The following example illustrates the issue:

```
In [1]: from astropy import units as u

In [2]: import numpy as np

In [4]: q = np.array([1,2,3]) * u.m

In [5]: q[1]
ERROR: TypeError: The value must be a valid Python numeric type. [astropy.units.quantity]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 q[1]

/Users/tom/Library/Python/3.2/lib/python/site-packages/astropy-0.3.dev3053-py3.2-macosx-10.6-x86_64.egg/astropy/units/quantity.py in __getitem__(self, key)
309 raise TypeError("'{cls}' object with a scalar value does not support indexing".format(cls=self.__class__.__name__))
310 else:
--> 311 return Quantity(self.value[key], unit=self.unit)
312
313 def __len__(self):

/Users/tom/Library/Python/3.2/lib/python/site-packages/astropy-0.3.dev3053-py3.2-macosx-10.6-x86_64.egg/astropy/units/quantity.py in __init__(self, value, unit)
77
78 def __init__(self, value, unit):
---> 79 self._value = _validate_value(value)
80 self._unit = Unit(unit)
81

/Users/tom/Library/Python/3.2/lib/python/site-packages/astropy-0.3.dev3053-py3.2-macosx-10.6-x86_64.egg/astropy/units/quantity.py in _validate_value(value)
52 value_obj = np.array(value, copy=True)
53 else:
---> 54 raise TypeError("The value must be a valid Python numeric type.")
55
56 return value_obj

TypeError: The value must be a valid Python numeric type.
```

Slicing works though:

```
In [6]: q[1:2]
Out[6]:
```

Whoever has time to look at this first should assign themselves to this issue.