Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): Add mermaid output to show_graph #20607

Closed
wants to merge 4 commits into from

Conversation

kjgoodrick
Copy link

This is a fix for #12075 adding mermaid output to polars. I have decided that it makes more sense to have mermaid output come from the show_graph method instead of explain because explain appears to be for generating printable representations of the query plan wheras show_graph is for generating strings that can be fed to a visualization engine (currently just graphviz)

In addition to being able to output mermaid strings this PR will output a mermaid diagram if the user is in a notebook and graphviz is not installed. I think at some point it may be a better user experience to always export mermaid instead of the SVG in notebooks, but for now I did not want to change the behavior.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jan 8, 2025
Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 12.00000% with 22 lines in your changes missing coverage. Please review.

Project coverage is 79.03%. Comparing base (785bb1e) to head (bbafade).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
py-polars/polars/_utils/various.py 8.33% 21 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20607      +/-   ##
==========================================
+ Coverage   79.00%   79.03%   +0.03%     
==========================================
  Files        1566     1557       -9     
  Lines      221034   220550     -484     
  Branches     2510     2514       +4     
==========================================
- Hits       174623   174308     -315     
+ Misses      45837    45667     -170     
- Partials      574      575       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kjgoodrick
Copy link
Author

@akshayka @mscolnick

Copy link
Collaborator

@alexander-beedie alexander-beedie left a comment

Choose a reason for hiding this comment

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

@kjgoodrick: FYI, needs a small update (some triple-quotes where you currently have single-quotes with multiline strings, I think) due to the requirement to support py3.9.

I'll try it out once fixed, but looks like it could be a handy/straightforward addition 🤔

@eitsupi
Copy link
Contributor

eitsupi commented Jan 8, 2025

Is there any reason why this is not implemented in Rust?

@ritchie46
Copy link
Member

This should not be implemented in python.

@kjgoodrick
Copy link
Author

@alexander-beedie Thanks for pointing this out, I have updated the code such that it is now python 3.9 compatible.

@eitsupi @ritchie46 Thank you both for the comments, I think it should be fairly straightforward to move the mermaid generation code to rust and update the show_graph logic to handle some of the logic that is currently in display_dot_graph. I will open a new PR when that is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants