[Numpy-discussion] bug in genfromtxt
Skipper Seabold
jsseabold at gmail.com
Tue Oct 12 17:46:07 EDT 2010
With names=True, if you specify the dtype manually and specify
usecols, it doesn't grab the correct names along with the columns.
Should be a simple fix, but haven't had time to write a patch yet.
from stringIO import stringIO
import numpy as np
np.__version__
#1.5.0
s = StringIO("col0,col1,col2,col3,col4\n0,1,2,3,4\n0,1,2,3,4\n0,1,2,3,4")
arr = np.genfromtxt(s, names=True, usecols=(0,2,4), delimiter=",",
dtype=['int','int','int'])
arr.dtype.names
#('col0', 'col1', 'col2')
Interestingly in trying to reproduce, I mistyped the dtype and got the
expected names (but no error on my bad dtype).
arr = np.genfromtxt(s, names=True, usecols=(0,2,4), delimiter=",",
dtype=['int','int','int','int','int'])
arr.dtype.names
#('col0', 'col2', 'col4')
It also works as expected with dtype=None.
Ticket here: http://projects.scipy.org/numpy/ticket/1636
Skipper
More information about the NumPy-Discussion
mailing list