Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG? Parser adds empty MultiIndex level names #10984

Closed
chris-b1 opened this issue Sep 3, 2015 · 6 comments · Fixed by #30646
Closed

BUG? Parser adds empty MultiIndex level names #10984

chris-b1 opened this issue Sep 3, 2015 · 6 comments · Fixed by #30646
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@chris-b1
Copy link
Contributor

chris-b1 commented Sep 3, 2015

In [179]: midx = MultiIndex.from_tuples([('A', 1, 2), ('A', 1, 2), ('B', 1, 2)])
    ...:  df = DataFrame(np.random.randn(3, 3), index=midx,
    ...:                 columns=['x', 'y', 'z'])

In [180]: df
Out[180]: 
            x         y         z
A 1 2  1.236013  2.239172 -1.513059
    2 -0.159620  0.222250 -1.635894
B 1 2  0.211036 -0.441065 -0.661737

In [181]: df.to_csv('test.csv')

In [182]: result = pd.read_csv('test.csv', index_col=[0, 1, 2])

In [183]: result
Out[183]: 
                                x         y         z
Unnamed: 1 Unnamed: 2                              
A 1          2           1.236013  2.239172 -1.513059
             2          -0.159620  0.222250 -1.635894
B 1          2           0.211036 -0.441065 -0.661737
@jreback
Copy link
Contributor

jreback commented Sep 4, 2015

use read_csv

from_csv has certain defaults to make it a mirror of to_csv exactly

@chris-b1
Copy link
Contributor Author

chris-b1 commented Sep 4, 2015

Updated example, same behavior. Original block was from a test here with a TODO:
https://github.com/pydata/pandas/blob/master/pandas/tests/test_frame.py#L6340

@jreback
Copy link
Contributor

jreback commented Sep 4, 2015

look for an open issue about this
iirc this was noted when I originally wrote this

@chris-b1
Copy link
Contributor Author

chris-b1 commented Sep 4, 2015

Hmm, not have any luck finding one, although I might just have the wrong search terms. Here's the pr where that line was added (changing default of assert_frame_equal to include names) #2964

@jreback
Copy link
Contributor

jreback commented Sep 4, 2015

xref #6618

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string IO CSV read_csv, to_csv MultiIndex labels Sep 4, 2015
@mroeschke
Copy link
Member

Looks like names are not added anymore. Could use a test.

In [145]: pd.read_csv('test.csv', index_col=[0, 1, 2])
Out[145]:
              x         y         z
A 1 2  0.593604 -0.836343 -0.786727
    2 -0.077489 -0.829363 -0.453257
B 1 2  0.131251 -0.622905  0.672914

In [146]: pd.__version__
Out[146]: '0.26.0.dev0+576.gde67bb72e'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed IO CSV read_csv, to_csv MultiIndex Output-Formatting __repr__ of pandas objects, to_string labels Oct 16, 2019
@simonjayhawkins simonjayhawkins added this to the 1.0 milestone Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants