Skip to content

BUG: output of df.to_string depends on whether columns is a CategoricalIndex or not #35439

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

Closed
topper-123 opened this issue Jul 28, 2020 · 2 comments · Fixed by #35440
Closed
Labels
Bug Index Related to the Index class or subclasses Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@topper-123
Copy link
Contributor

topper-123 commented Jul 28, 2020

The output of df.to_string is different if the columns is a CategoricalIndex rather than a normal Index:

>>> data = [[4, 2], [3, 2], [4, 3]]
>>> cols = ["aaaaaaaaa", "b"]
>>>  pd.DataFrame(data, columns=cols)
   aaaaaaaaa  b
0          4  2
1          3  2
2          4  3
>>> pd.DataFrame(data, columns=pd.CategoricalIndex(cols))
   aaaaaaaaa  b
0          4          2
1          3          2
2          4          3

We can see that the width of the "b" column depends on the width of the "a" column, if the columns are a CategoricalIndex.

These two examples should return the same repr.

@topper-123 topper-123 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 28, 2020
@topper-123 topper-123 added Index Related to the Index class or subclasses Output-Formatting __repr__ of pandas objects, to_string and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2020
@simonjayhawkins
Copy link
Member

Thanks @topper-123 for the report. This was OK for earlier versions?

@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Jul 29, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1.1 milestone Jul 29, 2020
@topper-123
Copy link
Contributor Author

Yes, this is a regression since v1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses Output-Formatting __repr__ of pandas objects, to_string Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants