Skip to content

fix: handle list-type tooltip encoding in altair chart (#9167)#9175

Merged
mscolnick merged 1 commit intomainfrom
ms/fix/9167
Apr 15, 2026
Merged

fix: handle list-type tooltip encoding in altair chart (#9167)#9175
mscolnick merged 1 commit intomainfrom
ms/fix/9167

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

_has_binning() and _get_binned_fields() iterated over
spec["encoding"].values() and called dict methods (.get(), in) on
each value. When tooltip is defined as a list of multiple tooltips,
the encoding value is a list instead of a dict, causing
AttributeError: 'list' object has no attribute 'get'.

Skip list-type encoding values (like tooltip arrays) since they cannot
contain binning configuration.

Closes #9167

`_has_binning()` and `_get_binned_fields()` iterated over
`spec["encoding"].values()` and called dict methods (`.get()`, `in`) on
each value. When `tooltip` is defined as a list of multiple tooltips,
the encoding value is a list instead of a dict, causing
`AttributeError: 'list' object has no attribute 'get'`.

Skip list-type encoding values (like tooltip arrays) since they cannot
contain binning configuration.

Closes #9167
Copilot AI review requested due to automatic review settings April 13, 2026 20:15
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 13, 2026 8:16pm

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in mo.ui.altair_chart when Vega-Lite encodings include list-valued channels (notably tooltip=[...]), by preventing _has_binning() / _get_binned_fields() from calling dict methods on list objects.

Changes:

  • Skip list-valued entries when scanning spec["encoding"] for binning metadata.
  • Add regression tests covering tooltip-as-list behavior for _get_binned_fields(), _has_binning(), and a smoke test for altair_chart(...).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
marimo/_plugins/ui/_impl/altair_chart.py Avoids AttributeError by skipping list-valued encoding channels during binning detection.
tests/_plugins/ui/_impl/test_altair_chart.py Adds tests to ensure tooltip lists don’t crash binning detection or altair_chart.
Comments suppressed due to low confidence (1)

marimo/_plugins/ui/_impl/altair_chart.py:96

  • _get_binned_fields() currently continues on list-valued encoding channels. This avoids the tooltip crash, but it also drops any binned field definitions contained inside arrays (valid for channels like tooltip/detail/order). That can lead to incorrect binned_fields, and downstream selection filtering may treat binned selections as non-binned. Consider walking list items and extracting bin from any dict elements rather than skipping the whole list.
    for encoding in spec["encoding"].values():
        if isinstance(encoding, list):
            continue
        if encoding.get("bin"):
            # Get the field name
            field = encoding.get("field")
            if field:
                binned_fields[field] = encoding["bin"]

Comment thread marimo/_plugins/ui/_impl/altair_chart.py
Copy link
Copy Markdown
Member

@kirangadhave kirangadhave left a comment

Choose a reason for hiding this comment

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

🚀

@mscolnick mscolnick merged commit 386cba6 into main Apr 15, 2026
38 of 49 checks passed
@mscolnick mscolnick deleted the ms/fix/9167 branch April 15, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_get_binned_fields() in _altair_chart.py fails with multiple tooltips defined as a list

3 participants