REF: route groupby plotting through dedicated _python_apply_plot#65927
Open
jbrockmendel wants to merge 2 commits into
Open
REF: route groupby plotting through dedicated _python_apply_plot#65927jbrockmendel wants to merge 2 commits into
jbrockmendel wants to merge 2 commits into
Conversation
Groupby plotting (the .plot accessor, .plot.<method>, and .hist) went through _python_apply_general, relying on the group key being pinned to each group's name attribute as a side effect of the general apply path. Route it through a dedicated _python_apply_plot helper that labels each Series group with its key explicitly. Behavior is unchanged; this decouples plotting from the name-pinning side effect (groundwork for GH#41090). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Behavior-neutral refactor split off from GH-64660 (the GH-41090 group-key name-pinning deprecation).
Groupby plotting — the
.plotaccessor,.plot.<method>(), and.hist()— previously went through_python_apply_general, relying on the group key being pinned to each group'snameattribute as a side effect of the general apply path. This routes it through a dedicated_python_apply_plothelper that labels each Series group with its key explicitly.This is a pure refactor (no behavior change). It expresses plotting's actual need — give each Series group its key so plotting methods can use it for legend labels — directly, instead of piggybacking on the name-pinning side effect. It also stands as groundwork for GH-41090: once plotting no longer depends on the pin, that deprecation can be enforced without touching plotting.
_python_apply_plotis equivalent to the general path for plotting:(key, group)iteration (get_iteratoriszip(result_index, _get_splitter(data)), exactly whatapply_groupwisezips).not_indexed_sameis hardcodedTrue— plotting always returns matplotlib objects, which are never index-like, so the general path already computedTruehere..name.Test plan
pandas/tests/plotting/test_groupby.pypasses, including a newtest_groupby_plot_series_with_legendlocking in key-as-legend-label through the new path🤖 Generated with Claude Code