Open dmadisetti opened 5 days ago
This is because BarContainer
is a subclass of tuple
, and our structures formatter flattens it. We do have a formatter for BarContainer
.
Relevant code:
https://github.com/marimo-team/marimo/blob/main/marimo/_utils/flatten.py#L129-L140
We could either:
_flatten
(ugly but no second-order effects)Hack: special case bar container in _flatten (ugly but no second-order effects)
could we add a formatter for BarContainer
in matplotlib_formatters.py
? and then it is not a special case in _flatten
We already have a formatter for it, which is why emitting a bare BarContainer
works.
The issue arises when a BarContainer
is in a structure, which is when flatten kicks in and the isinstance(item, tuple)
check takes priority leading it to being unpacked instead of formatted.
And can't just naively check for the existence of a formatter first, since tuple
etc have formatters (ie flatten).
What about checking to see if the item belongs in formatters? And if it does, not continuing to unpack
if isinstance(obj, FORMATTERS.keys()):
# get formatter, format and kick out
That way not barcontainer specific, and behavior is handled only for defined formatters
Something like that could work. But tuple
, list
, and dict
are all in FORMATTERS.keys()
, and using their formatters would lead to unbounded recursion.
Describe the bug
On
marimo iterates over the bar container to produce many duplicate plots:
Expected type
nd.array
,nd.array
,barcontainer
: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.htmlOutputting the bar container by itself works as expected:
but wrapping it in an iterable produces bad news:
Environment
head, see: https://marimo.app/l/uudxmj
Code to reproduce