You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MNT]: Refactor grouped_bar orientation logic using shared common_kwargs #30729
In the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations.
Tim Hoffmann suggested a more maintainable approach by introducing a shared common_kwargs dictionary to consolidate repeated parameters such as align, label, color, and hatch.
Current Code Snippet::
if orientation == "vertical":
bc = self.bar(lefts, hs, width=bar_width, align="edge",
label=label, color=color, hatch=hatch_pattern, **kwargs)
else:
bc = self.barh(lefts, hs, height=bar_width, align="edge",
label=label, color=color, hatch=hatch_pattern, **kwargs)
Proposed Refactor::
common_kwargs = dict(align="edge", label=label, color=color, hatch=hatch_pattern)
if orientation == "vertical":
bc = self.bar(lefts, hs, width=bar_width, **common_kwargs, **kwargs)
else:
bc = self.barh(lefts, hs, height=bar_width, **common_kwargs, **kwargs)
Benefits
Eliminates redundant code across orientation branches.
Reduces likelihood of introducing inconsistencies or errors during future updates.
Makes the code cleaner and easier to maintain.
Removes the need for a separate orientation-specific test since the logic path becomes symmetrical.
Reference:
Suggestion from @timhoffm in PR ENH: Add broadcasted hatch to grouped_bar #30683
Proposed fix
common_kwargs = dict(align="edge", label=label, color=color, hatch=hatch_pattern)
if orientation == "vertical":
bc = self.bar(lefts, hs, width=bar_width, **common_kwargs, **kwargs)
else:
bc = self.barh(lefts, hs, height=bar_width, **common_kwargs, **kwargs)
This is a small internal code change. Please do it directly in the PR. You are touching that code anyway. (Or don't and argue in the comment why it should not be done).
Activity
story645 commentedon Nov 5, 2025
These sorta pure implementation questions should mostly be handled in the pull request as part of the pull request discussion.
The main reasons to open an issue are if the implementation discussion:
timhoffm commentedon Nov 5, 2025
This is a small internal code change. Please do it directly in the PR. You are touching that code anyway. (Or don't and argue in the comment why it should not be done).