PyTables/PyTables — Issue #135: Allow repeated indices to align with numpy's index behavior
Author: askjak
Created: 2012-03-06 09:25:48+00:00
State: open

I would like to request the following feature that would allow repeated indices to align with numpy's index behavior. There are many cases where this would extremely handy. Below is script that exposes the difference.

import numpy as np
import tables

N=5
M=5

A=np.arange(N*M, dtype=float).reshape(N,M)

with tables.openFile("file.h5", "w") as f:

B=f.createCArray(f.root,"B", tables.Float64Atom(), (N,M))
B[:]=A

print A[0,[0,1,2]]
print B[0,[0,1,2]]

print A[0,[0,1,2,0]]
print B[0,[0,1,2,0]] # However: IndexError: Selection lists cannot have repeated values

$ python repeated_indices.py
[ 0. 1. 2.]
[ 0. 1. 2.]
[ 0. 1. 2. 0.]
Traceback (most recent call last):
File "repeated_indices.py", line 19, in
print B[0,[0,1,2,0]] # However: IndexError: Selection lists cannot have repeated values
File "/share/distro/python/2.7.2/lib/python2.7/site-packages/tables/array.py", line 692, in __getitem__
selection, reorder, shape = self._fancySelection(key)
File "/share/distro/python/2.7.2/lib/python2.7/site-packages/tables/array.py", line 622, in _fancySelection
"Selection lists cannot have repeated values")
IndexError: Selection lists cannot have repeated values