diff --git a/plotly/express/_core.py b/plotly/express/_core.py index 9fbf526cde..2756346c55 100644 --- a/plotly/express/_core.py +++ b/plotly/express/_core.py @@ -588,7 +588,8 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref): and attr_name == "z" ): # ensure that stuff like "count" gets into the hoverlabel - mapping_labels[attr_label] = "%%{%s}" % attr_name + if attr_label is not None: + mapping_labels[attr_label] = "%%{%s}" % attr_name if trace_spec.constructor not in [go.Parcoords, go.Parcats]: # Modify mapping_labels according to hover_data keys # if hover_data is a dict diff --git a/tests/test_optional/test_px/test_px_functions.py b/tests/test_optional/test_px/test_px_functions.py index 0814898f89..2822a931fd 100644 --- a/tests/test_optional/test_px/test_px_functions.py +++ b/tests/test_optional/test_px/test_px_functions.py @@ -619,3 +619,13 @@ def test_timeline_cols_already_temporal(constructor, datetime_columns): assert len(fig.data) == 3 assert fig.layout.xaxis.type == "date" assert fig.layout.xaxis.title.text is None + + +def test_empty_histogram(): + """Empty px.histogram() should not raise, matching scatter/bar/pie behavior. + + Regression test for https://github.com/plotly/plotly.py/issues/5534 + """ + fig = px.histogram() + assert len(fig.data) == 1 + assert fig.data[0].type == "histogram"