Skip to content

Commit 6f4493c

Browse files
authored
Merge pull request #5535 from tysoncung/fix-empty-histogram-crash
fix: handle empty px.histogram() by skipping None label in hover template
2 parents c7bffb9 + c10fb9c commit 6f4493c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

plotly/express/_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,8 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
588588
and attr_name == "z"
589589
):
590590
# ensure that stuff like "count" gets into the hoverlabel
591-
mapping_labels[attr_label] = "%%{%s}" % attr_name
591+
if attr_label is not None:
592+
mapping_labels[attr_label] = "%%{%s}" % attr_name
592593
if trace_spec.constructor not in [go.Parcoords, go.Parcats]:
593594
# Modify mapping_labels according to hover_data keys
594595
# if hover_data is a dict

tests/test_optional/test_px/test_px_functions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,13 @@ def test_timeline_cols_already_temporal(constructor, datetime_columns):
619619
assert len(fig.data) == 3
620620
assert fig.layout.xaxis.type == "date"
621621
assert fig.layout.xaxis.title.text is None
622+
623+
624+
def test_empty_histogram():
625+
"""Empty px.histogram() should not raise, matching scatter/bar/pie behavior.
626+
627+
Regression test for https://github.com/plotly/plotly.py/issues/5534
628+
"""
629+
fig = px.histogram()
630+
assert len(fig.data) == 1
631+
assert fig.data[0].type == "histogram"

0 commit comments

Comments
 (0)