Skip to content

new repr_html makes tutorials too long #9249

Closed

Description

@drammock

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:

  1. live with it
  2. go around putting _ = before all the cases where we want to suppress the HTML output
  3. is there a way to only show the nice table when the object is explicitly printed?

WDYT @vagechirkov @hoechenberger et al?

Activity

  1. larsoner commented on Apr 5, 2021

    @larsoner
    Member

    I would suggest a different solution:

    • 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).

  2. hoechenberger commented on Apr 5, 2021

    @hoechenberger
    Member

    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_STYLE setting to control the repr (text or html)

  3. vagechirkov commented on Apr 6, 2021

    @vagechirkov
    Contributor

    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

  4. drammock commented on Apr 6, 2021

    @drammock
    MemberAuthor

    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.

  5. larsoner commented on Apr 6, 2021

    @larsoner
    Member

    Comment filtering should come for free but if it doesn't it should be at most one more SG line to update

  6. larsoner commented on Apr 6, 2021

    @larsoner
    Member

    ... 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions