bcolz icon indicating copy to clipboard operation
bcolz copied to clipboard

fromiter - unable to specify names

Open de-code opened this issue 8 years ago • 2 comments

It appears it isn't possible to specify with the names when using fromiter:

Based on the tutorial:

N = 10
bcolz.fromiter(((i,i*i) for i in xrange(N)), dtype="i4,f8", count=N, names=['a', 'b'])

Expected: ctable with the columns 'a' and 'b'

Instead: Exception claiming that the lengths don't match. That is because the code in fromiter is creating an empty ctable where it passes through the keyword arguments (including names) and then adds columns. That means at the creation time len(columns) is zero.

de-code avatar Sep 27 '17 07:09 de-code

not tried, but I think you can pass the names in the dtype:

N = 10
dtype = [('a', 'i4'), ('b', 'f8')]
bcolz.fromiter(((i,i*i) for i in xrange(N)), dtype=dtype, count=N)

jdavid avatar Jun 05 '18 10:06 jdavid

Including the names in the dtype as jdavid suggests does work.

This has very poor documentation, though. From readthedocs:

kwargs : list of parameters or dictionary

Any parameter supported by the carray/ctable constructors.

And the result:

ValueError: columns and names must have the same length

Which gives no information about columns or names, nor is there any way to find out what the problem is besides looking at the source. It would save a lot of headaches to have more informative error messages.

ckingdev avatar Jul 02 '18 06:07 ckingdev