GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: handle empty px.histogram() by skipping None label in hover template by tysoncung · Pull Request #5535 · plotly/plotly.py

Conversation

@tysoncung

@tysoncung tysoncung commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Summary

px.histogram() crashes with TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' when called with no data arguments, while other chart types like px.scatter(), px.bar(), and px.pie() handle empty invocations correctly.

Root Cause

The histogram-specific hover label path in _core.py unconditionally adds an entry to mapping_labels even when no column is specified. When no data is provided, attr_label is None (from get_decorated_label(args, None, 'x')), resulting in a {None: '%{x}'} entry. The hover template list comprehension then fails:

hover_lines = [k + "=" + v for k, v in mapping_labels_copy.items()]
#              None + "=" + ...  → TypeError

Fix

Skip adding to mapping_labels when attr_label is None, consistent with how other chart types handle empty invocations (they never reach the mapping_labels code path since their attrs check attr_value is not None first).

Test

Added test_empty_histogram to verify px.histogram() returns a valid figure without raising.

Fixes #5534

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tysoncung
fix: handle empty histogram() by skipping None label in hover template
c10fb9c
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
emilykl self-requested a review March 10, 2026 17:53
emilykl
emilykl approved these changes Mar 10, 2026
View reviewed changes

@emilykl emilykl left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@emilykl
emilykl merged commit 6f4493c into plotly:main Mar 10, 2026
8 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@emilykl emilykl emilykl approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG]: creating empty px.histogram() results in an error

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@tysoncung @emilykl
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.