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

IPython cell magic for enabling Treescope in a single cell #5

Open
JEM-Mosig opened this issue Jul 31, 2024 · 3 comments
Open

IPython cell magic for enabling Treescope in a single cell #5

JEM-Mosig opened this issue Jul 31, 2024 · 3 comments
Labels
feature-request New feature or request

Comments

@JEM-Mosig
Copy link

I'd like to get the treescope visualizations in notebooks only if I decorate a cell with %%autovisualize. However, %%autovisualize doesn't seem to have any effect. I can only use treescope everywhere (with basic_interactive_setup()) or nowhere.

image

I am aware of treescope.show, but I'd still like to use %%autovisualize because it is nicely separated from the code content of the cell.

Thank you for sharing this great library!

@danieldjohnson danieldjohnson added bug Something isn't working and removed bug Something isn't working labels Jul 31, 2024
@danieldjohnson
Copy link
Collaborator

Ah, this isn't actually what %%autovisualize is intended to be used for!

The %%autovisualize magic turns on automatic array visualization for the active Treescope renderer, but doesn't enable the renderer itself. This means that calls to treescope.show that happen inside an %%autovisualize cell will show visual summaries of array data, even if array visualization was turned off during initial setup. Conversely, %%autovisualize None will omit array visualizations and instead show the numerical values in text form.

It sounds like you'd like to have a cell magic that displays the output with Treescope instead of displaying it with the ordinary IPython pretty-printer?

I'm not sure how doable this would be in IPython. I suppose it might be possible to make a cell magic that wraps the final cell output with treescope.show, but this would also prevent accessing the cell output with the outputs dictionary Out[...], so I don't think it should be the default behavior of %%autovisualize.

I think for now it would be easiest to just use treescope.show directly when you want to visualize the final cell output.

@danieldjohnson danieldjohnson changed the title %%autovisualize does not work as expected IPython cell magic for enabling Treescope in a single cell Jul 31, 2024
@danieldjohnson danieldjohnson added the feature-request New feature or request label Jul 31, 2024
@JEM-Mosig
Copy link
Author

Thanks for the quick feedback!

It sounds like you'd like to have a cell magic that displays the output with Treescope instead of displaying it with the ordinary IPython pretty-printer?

Yes, this is what I mean. Sorry, I misunderstood the meaning of %%autovisualize.

I'm not sure how doable this would be in IPython

I am not familiar with how IPython works under the hood, but could the treescope visualizer check if the %%autovisualize is present, and if yes, just not do anything / act as identity function / print like it was the default IPython printer?

@danieldjohnson
Copy link
Collaborator

I'm not sure, it might be possible but I don't know exactly how that would work.

I think if this does get added, it will probably be a different cell magic, not %%autovisualize (since %%autovisualize already has a separate meaning).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants