fix: handle list-type tooltip encoding in altair chart (#9167)#9175
Merged
fix: handle list-type tooltip encoding in altair chart (#9167)#9175
Conversation
`_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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
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 foraltair_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()currentlycontinues 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 incorrectbinned_fields, and downstream selection filtering may treat binned selections as non-binned. Consider walking list items and extractingbinfrom 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"]
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.
_has_binning()and_get_binned_fields()iterated overspec["encoding"].values()and called dict methods (.get(),in) oneach value. When
tooltipis 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