astropy/astropy — pull request #838 by taldcroft (2013-03-01 14:52:24+00:00)
Title: Cannot index Table with np.where output

From David Buscher:

It appears that the astropy.tables module does not accept the same row
indexing syntax as the corresponding ndarray, particularly the syntax
output by np.where(), which is a tuple containing an ndarray. Example
below:
```
Python 2.7.3 |EPD 7.3-1 (64-bit)| (default, Apr 12 2012, 11:14:05)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "credits", "demo" or "enthought" for more information.
>>> import numpy as np
>>> from astropy.table import Table

>>> t=Table(np.reshape(np.arange(12),(4,3)))
>>> print t
col0 col1 col2
---- ---- ----
0 1 2
3 4 5
6 7 8
9 10 11

>>> rows=np.where(t["col0"]>5)
>>> print rows
(array([2, 3]),)

# ndarray version
>>> print np.array(t)[rows]
[(6, 7, 8) (9, 10, 11)]

# Tables version
>>> print t[rows[0]]
col0 col1 col2
---- ---- ----
6 7 8
9 10 11

>>> print t[rows]
ERROR: TypeError: unhashable type: 'numpy.ndarray' [astropy.table.table]
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/astropy/table/table.py",
line 1282, in __getitem__
if any(x not in set(self.colnames) for x in item):
File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/astropy/table/table.py",
line 1282, in
if any(x not in set(self.colnames) for x in item):
TypeError: unhashable type: 'numpy.ndarray'
```