Skip to content

Conversation

manzt
Copy link
Contributor

@manzt manzt commented Aug 12, 2025

These changes replace _ipython_display_ with _repr_mimebundle_ protocol displaying plots within notebooks. Previously, plotnine used _ipython_display_() for display, which works via side effects and assumes an IPython/Jupyter environment.

Since IPython 6.1 (May 2017), the _repr_mimebundle_() protocol allows objects to return display data instead of triggering side effects. This decouples rendering from IPython, letting any compatible frontend (e.g., Jupyter, marimo) handle presentation without requiring the object to be aware of the runtime.

The repr continues to generate a single format (PNG, SVG, etc.) based on configuration to match prior behavior with the _ipython_display_.

References:

These changes replace `_ipython_display_` with `_repr_mimebundle_`
protocol displaying plots within notebooks. Previously, plotnine used
`_ipython_display_()` for display, which works via side effects and
assumes an IPython/Jupyter environment.

Since IPython 6.1 (May 2017), the `_repr_mimebundle_()` protocol allows
objects to return display data instead of triggering side effects. This
decouples rendering from IPython, letting any compatible frontend (e.g.,
Jupyter, marimo) handle presentation without requiring the object to be
aware of the runtime.

The repr continues to generate a single format (PNG, SVG, etc.) based on
configuration to match prior behavior with the `_ipython_display_`.

References:
- https://ipython.readthedocs.io/en/stable/config/integrating.html
- https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.formatters.html
Copy link

codecov bot commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 44.95413% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.62%. Comparing base (08088a0) to head (74748e5).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
plotnine/composition/_compose.py 41.17% 19 Missing and 1 partial ⚠️
plotnine/ggplot.py 21.05% 14 Missing and 1 partial ⚠️
plotnine/_utils/context.py 62.06% 9 Missing and 2 partials ⚠️
plotnine/_utils/ipython.py 35.71% 9 Missing ⚠️
plotnine/_utils/quarto.py 50.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #969      +/-   ##
==========================================
- Coverage   86.69%   86.62%   -0.07%     
==========================================
  Files         194      194              
  Lines       13330    13360      +30     
  Branches     1639     1646       +7     
==========================================
+ Hits        11556    11573      +17     
- Misses       1228     1238      +10     
- Partials      546      549       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@has2k1
Copy link
Owner

has2k1 commented Aug 15, 2025

Thanks for this. I had not picked up on the precedence of _repr_mimebundle_ and also to support both printing with side-effects (where necessary) and otherwise without them.

Caused by newer version of pandas-stubs.
@has2k1 has2k1 merged commit 377ee83 into has2k1:main Aug 28, 2025
8 of 9 checks passed
@manzt manzt deleted the manzt/repr-mimebundle branch August 29, 2025 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants