[Numpy-discussion] Convert recarray to list (is this a bug?)

Yan Tang tang.yan@gmail....
Mon Jul 9 21:24:00 CDT 2012


Hi,

I noticed there is an odd issue when I am trying to convert a recarray to
list.  See below for the example/test case.

$ cat a.csv
date,count
2011-07-25,91
2011-07-26,118
$ cat b.csv
name,count
foo,1233
bar,100

$ python

>>> from matplotlib import mlab
>>> import numpy as np

>>> a = mlab.csv2rec('a.csv')
>>> b = mlab.csv2rec('b.csv')
>>> a
rec.array([(datetime.date(2011, 7, 25), 91), (datetime.date(2011, 7, 26),
118)],
      dtype=[('date', '|O8'), ('count', '<i8')])
>>> b
rec.array([('foo', 1233), ('bar', 100)],
      dtype=[('name', '|S3'), ('count', '<i8')])


>>> np.array(a.tolist()).tolist()
[[datetime.date(2011, 7, 25), 91], [datetime.date(2011, 7, 26), 118]]
>>> np.array(b.tolist()).tolist()
[['foo', '1233'], ['bar', '100']]


The odd case is, 1233 becomes a string '1233' in the second command.  But
91 is still a number 91.

Why would this happen?  What's the correct way to do this conversion?

Thanks.

-uris-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120709/e60a1e1d/attachment.html 


More information about the NumPy-Discussion mailing list