astropy/astropy — pull request #2477 by eteq (2014-05-13 18:18:36+00:00)
Title: Fix numpy integer table access in py 3.x

This fixes what I think is a bug in how `Table.__getitem__` works. In py 2.x, the following works fine:
```
t = Table(...)
idxs = np.random.randint(len(t), size=2)
t[idxs[0]]
```
But the exact same code fails in py 3.x with
```
ValueError: Illegal type for table item access``.
```
(I could have just done ``t[np.int64(0)]``, but this is the actual use case I encountered the problem.)

The reason this fails is that is that indexing an `np.random.randint` yields a ``np.int64`` numpy scalar, and in py 2.x, ``isinstance(np.int64(0), int)`` is True, but in py 3.x, it is **False**. I'm not sure why this is different, but the end result is that the `Table.__getitem__` doesn't correctly recognize that a numpy integer should be treated as an index.

This PR fixes that by checking for both python `int` and `np.int_`. Note that this *could* be updated by instead checking for ``np.int32`` and `np.int64` (and even ``np.int16`` and ``np.int8`` and the relevant ``uint``s). Or some other more complicated "check if a numpy integer type" might work. But this solves the most common use case, I think.

cc @taldcroft