Skip to content

python: bypass plotnine auto-closing comms #7657

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

Merged
merged 11 commits into from
May 22, 2025
Merged

Conversation

isabelizimm
Copy link
Contributor

@isabelizimm isabelizimm commented May 13, 2025

Release Notes

New Features

  • N/A

Bug Fixes

QA Notes

pip install plotnine

from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap
from plotnine.data import mtcars

(
    ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
    + geom_point()
    + stat_smooth(method="lm")
    + facet_wrap("gear")
)

Should create 1 plot with no errors. You can also check that in the logs, the plot comms are being used, rather than display_data

@:plots

Copy link

github-actions bot commented May 13, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:plots

readme  valid tags

@isabelizimm
Copy link
Contributor Author

wip for feedback, but i'll add a test before we merge this

Copy link
Contributor

@austin3dickey austin3dickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find! This branch seems to fix the weirdness in the linked issue.

@isabelizimm isabelizimm marked this pull request as ready for review May 14, 2025 20:13
@isabelizimm isabelizimm requested a review from seeM May 14, 2025 20:14
nstrayer
nstrayer previously approved these changes May 15, 2025
Copy link
Contributor

@nstrayer nstrayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great for me! This feels about as surgical as it could get in this case!

seeM
seeM previously approved these changes May 15, 2025
…n_ipkernel.py

Co-authored-by: Wasim Lorgat <[email protected]>
Signed-off-by: Isabel Zimmerman <[email protected]>
@isabelizimm isabelizimm dismissed stale reviews from seeM and nstrayer via b472a9a May 15, 2025 13:51
self.figure.set_layout_engine("tight")
try:
# plotnine plots use their own layout engine, do not override
if self.figure._layout_engine.__module__ == "plotnine._mpl.layout_engine":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the retina problems were stemming from us overriding plotnine's layout manager! updated so we don't override it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Can we use the public method self.figure.get_layout_engine()? Might also need to check that it isn't None. And it might be safer to do something like .startswith('plotnine') in case they move it around

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do we think of always leaving the layout engine alone if it is not None? I understand the sizing won't be exact, but it might be a simple escape hatch to respect user's settings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a better approach! We'd just need to double-check that it doesn't break any existing behavior. Might be covered by e2e tests.

Copy link
Contributor

@austin3dickey austin3dickey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic! what a bug

@isabelizimm isabelizimm merged commit 79b4e30 into main May 22, 2025
28 checks passed
@isabelizimm isabelizimm deleted the intrinsic-size-python branch May 22, 2025 18:08
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants