You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new _repr_html for Info, Raw, Epochs, and Evoked is pretty cool. But it has a drawback, which is that every time an instance is returned at the end of a tutorial cell, we get the full HTML repr (13 lines for a Raw). In some tutorials this happens multiple times, the extra information isn't always helpful, and it breaks up the flow of the lesson. For example, in this tutorial the HTML repr of Raw happens twice, once after a call of raw.crop(tmax=60).load_data() and once after raw.set_annotations(). The first occurence is maybe arguably useful (though not directly relevant to the tutorial's purpose) but IMO the second one is clearly not helpful. I scanned through the first ~15-20 tutorials and found that about 1/3 of them have 2 instances of a Raw HTML repr; I didn't check closely but I'd guess that many of them are extraneous / unneeded.
Possible solutions:
live with it
go around putting _ = before all the cases where we want to suppress the HTML output
is there a way to only show the nice table when the object is explicitly printed?
Enhance sphinx-gallery to allow per-block capture_repr config
In principle this should only require a few lines in Sphinx-gallery. And our default config can be allow-list style by setting capture_repr=() in conf.py, and in the blocks where we want it, enable it via # sphinx_gallery_capture_repr = ('_repr_html_',) or so (or vice-versa conf/inline for blocklist-style).
I keep going back and forth in my head whether collapsing by default is a good approach or not. In some contexts (like in Reports) I think we want expanded to be the default? In others (many, but not all, occurrences in the tutorials) we either don't want/need to see the repr, or we at least want it collapsed by default.
So assuming my option 3 isn't actually possible, I sort of lean toward what @larsoner suggests, even though it compels us to add extra sphinx-gallery control comments to the tutorials... assuming that (1) those comments will get filtered out of the rendered HTML tutorial like the sphinx_gallery_thumbnail_number comments do, and (2) we can do it cell-by-cell rather than document-by-document. If the comment filtering doesn't happen, we might as well just use _ = whatever since that's less to type and (possibly?) no more or less confusing to the reader.
Activity
larsoner commentedon Apr 5, 2021
I would suggest a different solution:
capture_reprconfigIn principle this should only require a few lines in Sphinx-gallery. And our default config can be allow-list style by setting
capture_repr=()inconf.py, and in the blocks where we want it, enable it via# sphinx_gallery_capture_repr = ('_repr_html_',)or so (or vice-versa conf/inline for blocklist-style).hoechenberger commentedon Apr 5, 2021
We could display a short summary and collapse the table by default.
Here's an example of a collapsible HTML representation using ipywidgets:
https://matthewrocklin.com/blog/2019/07/04/html-repr#logs
Here's a PR from xarray that adds a repr with collapsible elements:
https://github.com/pydata/xarray/pull/3425/files
They introduced a
DISPLAY_STYLEsetting to control the repr (text or html)vagechirkov commentedon Apr 6, 2021
I agree with @hoechenberger. I think it is better to collapse by default the long representations. I will create the draft PR with this feature
drammock commentedon Apr 6, 2021
I keep going back and forth in my head whether collapsing by default is a good approach or not. In some contexts (like in Reports) I think we want expanded to be the default? In others (many, but not all, occurrences in the tutorials) we either don't want/need to see the repr, or we at least want it collapsed by default.
So assuming my option 3 isn't actually possible, I sort of lean toward what @larsoner suggests, even though it compels us to add extra sphinx-gallery control comments to the tutorials... assuming that (1) those comments will get filtered out of the rendered HTML tutorial like the
sphinx_gallery_thumbnail_numbercomments do, and (2) we can do it cell-by-cell rather than document-by-document. If the comment filtering doesn't happen, we might as well just use_ = whateversince that's less to type and (possibly?) no more or less confusing to the reader.larsoner commentedon Apr 6, 2021
Comment filtering should come for free but if it doesn't it should be at most one more SG line to update
larsoner commentedon Apr 6, 2021
... but looking at the existing options there are no block specific comments in SG yet, but I don't see why we can't have/add them for this use case