tocsv, fromcsv changes order of larry #63

Closed
billherschel opened this Issue Sep 11, 2012 · 2 comments

Comments

Projects
None yet
2 participants

I'm not sure if this is an issue or a feature, but saving a larry as a csv using tocsv and reading from a csv using fromcsv changes the order of items in a larry.

The text file looks like I'd expect, so imagine this behavior comes from fromcsv.

from la import larry

y = larry([[1.0, 2.0], [3.0, 4.0]], [['b', 'a'], ['d', 'c']])

y.tocsv('a_file.csv',delimiter=',')

y
Out[4]:
label_0
b
a
label_1
d
c
x
array([[ 1., 2.],
[ 3., 4.]])

larry.fromcsv('a_file.csv',delimiter=',')
Out[5]:
label_0
a
b
label_1
c
d
x
array([[ 4., 3.],
[ 2., 1.]])

Owner

kwgoodman commented Sep 11, 2012

Yes, under the hood to/from csv uses to/fromtuples:

In [1]: y = la.larry([[1.0, 2.0], [3.0, 4.0]], [['b', 'a'], ['d', 'c']])
In [2]: y.totuples()
Out[2]: [('b', 'd', 1.0), ('b', 'c', 2.0), ('a', 'd', 3.0), ('a', 'c', 4.0)]
In [3]: la.larry.fromtuples(y.totuples())
Out[3]: 
label_0
    a
    b
label_1
    c
    d
x
array([[ 4.,  3.],
       [ 2.,  1.]])

totuples flattens the larry and therefore the ordering of labels is lost.

The recommended method to archive larrys is in HDF5 (using h5py):

In [1]: y = la.larry([[1.0, 2.0], [3.0, 4.0]], [['b', 'a'], ['d', 'c']])
In [2]: la.save('y.h5', y, 'y')
In [3]: la.load('y.h5', 'y')
Out[3]: 
label_0
    b
    a
label_1
    d
    c
x
array([[ 1.,  2.],
       [ 3.,  4.]])
Owner

kwgoodman commented Apr 24, 2013

Duplicate of issue #66.

kwgoodman closed this Apr 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment