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] Misaligned column headers of pandas DataFrame in IPython when using rich.pretty #1256

Closed
dlukes opened this issue May 27, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@dlukes
Copy link

dlukes commented May 27, 2021

Compare the vanilla Out[2] with Out[4] prettified by rich: the column headers are no longer right-aligned:

ipython

The fix should be easy -- just make rich put the column headers on a separate line, like the vanilla representation. But maybe there's a catch? One thing that comes to mind is that maybe this can't be fully fixed on rich's side -- maybe it's an unfortunate interaction between rich, ipython and pandas? FWIW, the problem doesn't occur in the regular Python REPL:

python

@willmcgugan
Copy link
Collaborator

The problem is that IPython prints the Out[2] text and leaves the cursor at the next character, where Rich starts printing from. This is fine if you are printing something on a single line, but it breaks formatted columns as you've demonstrated.

I'm assuming that IPython has a special case for output that has newlines. If there is a newline character it will start the output on the following line and not the line containing Out[X]. Rich could probably replicate this behavior.

@dlukes
Copy link
Author

dlukes commented May 27, 2021

I'm assuming that IPython has a special case for output that has newlines. If there is a newline character it will start the output on the following line and not the line containing Out[X]. Rich could probably replicate this behavior.

That sounds great as far as I'm concerned :)

@willmcgugan willmcgugan added bug Something isn't working and removed Needs triage labels Jun 25, 2021
@willmcgugan
Copy link
Collaborator

Can you give 10.5.0 a try and let me know if that fixes it?

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jul 5, 2021
10.5.0:

Fixed

Fixed Pandas objects not pretty printing Textualize/rich#1305
Fixed Textualize/rich#1256
Fixed typing with rich.repr.auto decorator
Fixed repr error formatting Textualize/rich#1326

Added

Added new_line_start argument to Console.print
Added Segment.divide method
Added Segment.split_cells method
Added segment.SegmentLines class
@dlukes
Copy link
Author

dlukes commented Jul 5, 2021

Works like a charm, thank you very much!

@dlukes dlukes closed this as completed Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants