fix: handle empty px.histogram() by skipping None label in hover template#5535
Merged
emilykl merged 1 commit intoplotly:mainfrom Mar 10, 2026
Merged
Conversation
When px.histogram() is called with no data arguments, the histogram-
specific hover label path inserts a None key into mapping_labels
(because attr_label is None when no column is specified). The hover
template list comprehension then fails with:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
Skip adding to mapping_labels when attr_label is None, consistent
with how other chart types handle empty invocations.
Fixes plotly#5534
emilykl
approved these changes
Mar 10, 2026
Contributor
There was a problem hiding this comment.
Thanks for the fix @tysoncung !
That whole massive if statement inside make_trace_kwargs() is a bit messy. This is a perfectly reasonable fix and addresses the issue.
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.
Summary
px.histogram()crashes withTypeError: unsupported operand type(s) for +: 'NoneType' and 'str'when called with no data arguments, while other chart types likepx.scatter(),px.bar(), andpx.pie()handle empty invocations correctly.Root Cause
The histogram-specific hover label path in
_core.pyunconditionally adds an entry tomapping_labelseven when no column is specified. When no data is provided,attr_labelisNone(fromget_decorated_label(args, None, 'x')), resulting in a{None: '%{x}'}entry. The hover template list comprehension then fails:Fix
Skip adding to
mapping_labelswhenattr_labelisNone, consistent with how other chart types handle empty invocations (they never reach the mapping_labels code path since their attrs checkattr_value is not Nonefirst).Test
Added
test_empty_histogramto verifypx.histogram()returns a valid figure without raising.Fixes #5534