Polars LazyFrame show_graph
has poor graphic quality in Marimo
#3355
Labels
enhancement
New feature or request
show_graph
has poor graphic quality in Marimo
#3355
Description
I am submitting a PR for this suggestion.
When using polars LazyFrames it is often desirable to display the query plan prior to collecting the query. There are multiple ways to do this in Marimo.
show_graph
functionexplain
to output a text-based query planIt would be nice if Marimo could display high quality graphics for the query plan even when the user wants to view the optimized plan and/or doesn't have matplotlib / graphviz installed. It would also be nice if the graph followed the theme of the notebook (dark / light) and could nicely display plans that have many terms (e.g. a query that transforms many columns in one step).
Suggested solution
My suggestion is to register a polars extension that adds a marimo
mo
namespace to LazyFrames and allows users to display high quality query plan graphs in all situations with only a slight change to their code. This added polars extension code will be maintained within the marimo repository so that it will not require adding any code to the polars repository.Because marimo already has support for displaying mermaid graphs and polars can return the raw text defining the graph (in dot notation) it makes sense to parse this and convert to mermaid.
Once added this approach would allow for results that:
Alternative
Instead of outputting meramaid code it might be possible to recreate polars
_repr_html_
in order to display a high-quality image of the graph. However, this would require the user to have dot installed, would not change color with the user theme, and would not give the line wrapping behavior for wide graphs.Additional context
I think ultimately the best solution would be to have
show_graph
and_repr_html_
in polars recognize that they are in marimo and change their behavior. This would require their cooperation though, which is of unknown likelihood to me. I have written the implementation for the PR such that it would be easy for them to call marimo's functions if they detect a marimo environment (similar to what they already do for notebooks).This snippet could be added in to the polars
display_dot_graph
function after theraw_output
check to get the same behavior when using polars'show_graph
function.The text was updated successfully, but these errors were encountered: