[Numpy-discussion] Bug in rec.fromarrays ; plus one other possible bug

Pauli Virtanen pav@iki...
Wed Nov 25 09:05:21 CST 2009


ke, 2009-11-25 kello 09:48 -0500, Dan Yamins kirjoitti:
> Hi, I'm writing to report what looks like a two bugs in the handling
> of strings of length 0.  (I'm using 1.4.0.dev7746, on Mac OSX 10.5.8.
> The problems below occur both for python 2.5 compiled 32-bit as well
> as python2.6 compiled 64-bit). 
[clip]
> >>> Cols = [['test']*10,['']*10]
> 
> When not passing any dtype, this is created into a recarray with no
> problem:
> 
> >>> np.rec.fromarrays(Cols)
> rec.array([('test', ''), ('test', ''), ('test', ''), ('test', ''),
>        ('test', ''), ('test', ''), ('test', ''), ('test', ''),
>        ('test', ''), ('test', '')], 
>       dtype=[('f0', '|S4'), ('f1', '|S1')])
> 
> However, trouble arises when I try to pass a length-0 dtype
> explicitly.
> 
> >>> d = np.dtype([('A', '|S4'), ('B', '|S')])
> >>> np.rec.fromarrays(Cols,dtype=d) 
> recarray([('test', ''), ('\x00est', ''), ('\x00est', ''), ('\x00est',
> ''),
>        ('\x00est', ''), ('\x00est', ''), ('\x00est', ''), ('\x00est',
> ''),
>        ('\x00est', ''), ('\x00est', '')], 
>       dtype=[('A', '|S4'), ('B', '|S0')])

That certainly looks like a bug -- where does the \0 appear in front of
all but the first string?

File a ticket in Trac, http://projects.scipy.org/numpy/ -- small bugs
like this tend to get lost and forgotten in mailing list traffic.

-- 
Pauli Virtanen




More information about the NumPy-Discussion mailing list