[Numpy-discussion] at my wits end over an error message...

Zachary Pincus zachary.pincus at yale.edu
Sat Aug 30 23:10:10 EDT 2008


Hi Alan,

> Traceback (most recent call last):
>  File "/usr/local/lib/python2.5/site-packages/enthought.traits-2.0.4- 
> py2.5-linux-i686.egg/enthought/traits/trait_notifiers.py", line 325,  
> in call_1
>    self.handler( object )
>  File "TrimMapl_1.py", line 98, in _Run_fired
>    outdata = np.array(outdata, dtype=dtypes)
> TypeError: expected a readable buffer object

This would make it appear that the problem is not with numpy per se,  
but with the traits library, or how you're using it... I'm not too  
familiar with traits, so I can't really provide any advice there.

Can you disable whatever it is you're doing with traits for the time  
being, to see if that solves it? Maybe not have whatever notifier is  
presumably listening to outdata?

Also, for the record, your inner loop could be rendered in more  
idiomatic python as:

TYPICALLY_UINT_COLUMNS = set(['Track', 'Bin', 'code', 'horizon'])
......
        dtypes = []
        for var in self.var_list:
            if var in TYPICALLY_UINT_COLUMNS:
                dtypes.append(var, '<i8'))
            else :
                dtypes.append(var, '<f8'))
or even:

TYPICALLY_UINT_COLUMNS = set(['Track', 'Bin', 'code', 'horizon'])
dtypes = [(var, '<i8' if var in TYPICALLY_UINT_COLUMNS else '<f8') for  
var in self.var_list]

if you really want to break out the new ternary operator (py 2.5 and  
above).

Not that it matters at all in this case, but (in addition to being  
easier to read and write) loops like the above will be much faster  
than the original code if you've got some larger parsing operations to  
do. (Also, note that the 'in' operator works on lists and tuples as  
well as sets and dicts, but for the former two, it's a linear search,  
while for the latter, a hash lookup.)

Zach


> TYPICALLY_UINT_COLUMNS = ['Track', 'Bin', 'code', 'horizon']
> ......
>        dtypes = [ ]
>        for i in range(0, len(self.var_list)) :
>            if TYPICALLY_UINT_COLUMNS.count(self.var_list[i]) > 0:
>                dtypes.append((self.var_list[i], '<i8'))
>            else :
>                dtypes.append((self.var_list[i], '<f8'))
>        print "dtypes = ", dtypes
>        print outdata[0]
>        outdata = np.array(outdata, dtype=dtypes)





More information about the NumPy-Discussion mailing list