Fix plot_layout.__radd__ crash with plotnine's native composition operators#24
Merged
Merged
Conversation
…sition When `left | right` is evaluated, `ggplot.__or__` (from plotnine 0.15.x) creates a native `plotnine.composition.Beside`. When `+ plot_layout(widths=[1.6, 1])` is applied, the native Compose.__add__ doesn't recognise plot_layout as a composition modifier and passes it to the last ggplot via ggplot.__iadd__. This called plot_layout.__radd__(ggplot), which incorrectly set `ggplot.layout = self` (a plot_layout instance), overwriting plotnine's internal Layout object and causing AttributeError: 'plot_layout' object has no attribute 'setup' in ggplot._build(). Fix: guard plot_layout.__radd__ so that when cmp is a ggplot, it returns cmp unchanged rather than corrupting its layout attribute.
Copilot
AI
changed the title
[WIP] Fix failing GitHub Actions job 'build'
Fix plot_layout.__radd__ crash with plotnine's native composition operators
Jul 13, 2026
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The docs build was failing with
AttributeError: 'plot_layout' object has no attribute 'setup'when thecomposition-and-export.ipynbnotebook executed(left | right) + plot_layout(widths=[1.6, 1]).Root cause
In plotnine 0.15.x,
ggplot.__or__creates a nativeplotnine.composition.Beside. The nativeCompose.__add__doesn't recogniseplot_layoutas a composition modifier, so it delegates it to the last ggplot:When
ggplot._build()subsequently calledlayout.setup(layers, self), it foundplot_layout(which has nosetup) instead of plotnine's internalLayoutobject.Fix
Add a type guard in
plot_layout.__radd__: ifcmpis aggplotinstance (i.e. we're being added via native composition plumbing rather than directly to a plotnine_extraCompose), returncmpunchanged instead of corrupting its internal layout.plot_layoutapplied via a plotnine_extraCompose(e.g.Beside([p1, p2]) + plot_layout(...)) continues to work as before. The full custom-width/height feature is gated on plotnine ≥ 0.16.0 (which addsCompose.layout), consistent with the existing skip condition intest_plot_composition.py.