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
Fixed force_terminal on Jupyter #1918
Conversation
- prevent pandas dataframes getting rendered twice (string and html) - suppress matplotlib "<Figure ...>"
|
Why would you Please don't ask me to run something in Jupyter when you can paste a screenshot. |
|
Thank you for taking a look. Added a screenshot to the PR description, with markers on the behaviors that this PR tries to fix. |
|
Codecov Report
@@ Coverage Diff @@
## master #1918 +/- ##
==========================================
- Coverage 99.82% 99.80% -0.03%
==========================================
Files 71 71
Lines 6943 7057 +114
==========================================
+ Hits 6931 7043 +112
- Misses 12 14 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
I'm going to need an answer to my question, and some code I can cut and paste (or a notebook). |
|
Hi, I thought the quoted question was posted accidentally, my apology. The motivation to let Jupyter display cell outputs as colored ASCII rather than HTML are:
Below are the Python fragments to demonstrate the effect of this PR. You'll need to This fragment shows the effect on Jupyter "display_data". import pandas as pd
import rich
import rich.pretty
# Stuffs to display
d = {"A" * 200, "B" * 200}
df = pd.DataFrame({"a": range(3), "b": range(3)})
# Render "display_data" as colored text.
rich.reconfigure(force_terminal=True)
rich.pretty.install()
display(d, df, df["a"])
# Jupyter may surpress certain "display_data". For example, the semicolon makes Jupyter hide the
# "<AxesSubplot:...>" message.
df.plot();Here's the side-by-side comparison: One thing to also note is this PR changes only the ipython display hook, and makes no attempt to change the Console behavior. In the next example, the Jupyter "stream_output" still defaults to HTML, and will have to be specifically instructed for colored ASCII. # By default, render "stream_output" (e.g., stdout) as HTML.
rich.get_console().out("a", d)
# However, "stream_output" can be force rendered as colored text.
rich.console.Console(force_terminal=True, force_jupyter=False).out("a", d) |
|
@verdimrc Note that in order to automatically wrap long ASCII texts it seems that we just have to specify a |



Type of changes
Checklist
Description
Please describe your changes here. If this fixes a bug, please link to the issue, if possible.
Fixes behavior after running
rich.pretty.install()Jupyter Lab:<Figure size 432x288 with 1 Axes>on Matplotlib figuresforce_terminal=True. andforce_jupyter=None(orTrue), pandas dataframe must still be rendered once (i.e., the html repr).Screenshot below (from this notebook) compares the four behaviors: (1) vanilla Python, (2 and 3) rich, and (4) this PR.