assertion error when setting ctable by index
here is the code to reproduce:
import bcolz
import numpy as np
dtype = np.dtype([("a", np.object),
("b", np.uint8),
("c", np.int32),
("d", np.float32)
])
a = bcolz.ctable(np.empty(2, dtype=dtype), mode="w")
val = ("asdf", 22, 3333, 33.33)
a.append(val) # ok
a[2] # ok
# error
a[0] = val
Here is the error message:
Traceback (most recent call last):
File "t.py", line 19, in <module>
a[0] = val
File "/usr/local/src/gemini_install/data/anaconda/lib/python2.7/site-packages/bcolz/ctable.py", line 1155, in __setitem__
self.cols[name][key] = value[name]
File "bcolz/carray_ext.pyx", line 2153, in bcolz.carray_ext.carray.__setitem__ (bcolz/carray_ext.c:26591)
AssertionError
I actually get this:
AssertionError Traceback (most recent call last)
<ipython-input-11-519b9005455c> in <module>()
----> 1 a[0] = val
/home/esc/gw/bcolz/bcolz/ctable.pyc in __setitem__(self, key, value)
1153 # Then, modify the rows
1154 for name in self.names:
-> 1155 self.cols[name][key] = value[name]
1156 return
1157
/home/esc/gw/bcolz/bcolz/carray_ext.pyx in bcolz.carray_ext.carray.__setitem__ (bcolz/carray_ext.c:26488)()
2152 print nwrow
2153 print vlen
-> 2154 assert (nwrow == vlen)
2155
2156 # This is a private function that is specific for `eval`
AssertionError:
And in the above nwrow is 0 and vlen 1, whatever that might mean.
Also, I tried using unpacking, but this fails:
In [21]: a[0][0], a[0][1], a[0][2], a[0][3] = val
In [22]: a
Out[22]:
ctable((3,), [('a', 'O'), ('b', 'u1'), ('c', '<i4'), ('d', '<f4')])
nbytes: 46; cbytes: 48.44 KB; ratio: 0.00
cparams := cparams(clevel=5, shuffle=True, cname='blosclz')
[(None, 0, 0, 0.0) (None, 0, 0, 0.0) ('asdf', 22, 3333, 33.33000183105469)]
There is an error with setting values by index when using a carray with a string type:
In [1]: import bcolz
In [2]: b1 = bcolz.carray([None, None, 'World'])
In [3]: b1[0]
In [4]: b1[2]
Out[4]: 'World'
In [5]: b1[0] = 'Hello'
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-5-14e904eeb7fe> in <module>()
----> 1 b1[0] = 'Hello'
/home/esc/gw/bcolz/bcolz/carray_ext.pyx in bcolz.carray_ext.carray.__setitem__ (bcolz/carray_ext.c:26450)()
2150
2151 # Safety check
-> 2152 assert (nwrow == vlen)
2153
2154 # This is a private function that is specific for `eval`
AssertionError:
Update, it is only a problem if you use the 'object' type.
You could use "S4" as dtype for the string column, in which case the assignment works (but the defaults values are bust)...
Yeah, definitely object dtype issue:
In [2]: import bcolz
In [3]: b1 = bcolz.carray(['World'])
In [4]: b1
Out[4]:
carray((1,), |S5)
nbytes: 5; cbytes: 16.00 KB; ratio: 0.00
cparams := cparams(clevel=5, shuffle=True, cname='blosclz')
['World']
In [5]: b1.append('Hello')
In [6]: b1
Out[6]:
carray((2,), |S5)
nbytes: 10; cbytes: 16.00 KB; ratio: 0.00
cparams := cparams(clevel=5, shuffle=True, cname='blosclz')
['World' 'Hello']
In [7]: b1[0] = 'Hello'
In [8]: b1
Out[8]:
carray((2,), |S5)
nbytes: 10; cbytes: 16.00 KB; ratio: 0.00
cparams := cparams(clevel=5, shuffle=True, cname='blosclz')
['Hello' 'Hello']
there is something similar going on at #182 also releated to problems with the object dtype.
Can you submit a pull-request with a test-case that exposes the issue?