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
TIL that Info has a dedicated HTML representation, which is 🔥. However, I don't like that it doesn't show the same information as the standard text representation, for example:
Specifically, I really miss the channel names and I don't like that MEG types are always listed, but ideally there should be no differences at all except for a nicer rendering in HTML. WDYT?
No strong feeling from me. With the HTML we might be able to get away with more information even if we try to make it more consistent, for example we could probably do a 3-column table that has key / description / value (currently it's description / value), and keep the console more compact and closer to code with just key / value (what it is now).
Reacted by Clemens Brunner, Stefan Appelhoff and Mikolaj Magnuski
adding a key column as @larsoner suggests. Personally I'd but it in between the description and the value, possibly even as a parenthetical like "Highpass (highpass)" or "Sampling frequency (sfreq)"
suppressing things like 0 magnetometer
formatting the good channels to be \n separated instead of comma-separated (I think this was recently done by @larsoner for some other field in one of the other __html_repr__ methods? why not here too). If this is done, we should drop the words "and" and "channels" too
not sure what to do about harmonizing which fields are actually shown; to me it makes sense that they would match as @cbrnr suggests, but maybe there's a good reason they don't?
Ideally, we should only have to maintain __repr__ and just put its contents in a nice HTML table. I don't like that currently they contain different fields. I'm not even sure we need a description column for the fields when we could just use the keys (they should be self-explanatory and if not they are documented).
@cbrnr In my current PR #9828 on adding ICA to Report, I also reworked ICA.__repr__ and added ICA._repr_html_. To reduce code duplication and improve consistency between the two, I took the following approach:
I find it very strange to show different pieces of information depending on which backend is used. What exactly is the reason why showing exactly the same information is not feasible? The HTML repr is also just text which should easily fit in a terminal. This should not just synced for Info, but also for Raw, Epochs, and ICA(I don't think we have more).
What exactly is the reason why showing exactly the same information is not feasible?
HTML repr allows us to present data in true tables (that we will make collapsible soon, too), while you'll typically want a very concise repr on the terminal. Data can also be styled beyond just a tabular alignment in HTML, while this stuff isn't easy without introducing new dependencies on the terminal (e.g., via rich)
Also I think that when adding some of the HTML reprs, we didn't want to / dare to change the existing repr() output, but still wanted to take advantage of the features HTML offers.
That said, +1 on ensuring they're more synchronous, but please don't make the HTML repr just an ugly HTML-ified copy of the text repr. It can do much better than that.
I'm still -1 on using different reprs. I can already imagine the confusion when people notice that the output (repr) of an object in the interactive interpreter is widely different from inside a notebook. If you want to add nice HTML summaries I'd really prefer if that had its own dedicated method (e.g. raw.print_html() or even raw.print()). Changing the default repr is asking for trouble.
I would like to res this issue because I think the current dissociation between the two reprs are still very confusing (at least to me). Specifically, when writing some tutorial in a notebook-like environment, people should see the exact same output whether they are in a REPL or a notebook. In general, I prefer the REPL, but I write my tutorial with Quarto (which uses Jupyter notebook under the hood), so when I tell people to run e.g.
raw.info
I would like to see the REPL __repr__() and not _repr_html_().
@cbrnr +1 for adding a configuration option if Jupyter doesn't support this. The default should IMHO still be to use HTML repr in a Jupyter environment.
This would be great! And yes, HTML can remain the default for notebook envs.
Does anyone have an idea how to implement this technically? I briefly looked at how it's done in Scikit-learn, but couldn't really figure it out so I guess this will be a larger change.
I will also ask the IPython devs if they think this could be added on their end. Doesn't make a lot of sense that every package has to implement that.
Does anyone have an idea how to implement this technically? I briefly looked at how it's done in Scikit-learn, but couldn't really figure it out so I guess this will be a larger change.
Activity
agramfort commentedon Oct 11, 2021
larsoner commentedon Oct 11, 2021
No strong feeling from me. With the HTML we might be able to get away with more information even if we try to make it more consistent, for example we could probably do a 3-column table that has key / description / value (currently it's description / value), and keep the console more compact and closer to code with just key / value (what it is now).
agramfort commentedon Oct 11, 2021
drammock commentedon Oct 11, 2021
I propose:
keycolumn as @larsoner suggests. Personally I'd but it in between the description and the value, possibly even as a parenthetical like "Highpass (highpass)" or "Sampling frequency (sfreq)"0 magnetometergood channelsto be\nseparated instead of comma-separated (I think this was recently done by @larsoner for some other field in one of the other__html_repr__methods? why not here too). If this is done, we should drop the words "and" and "channels" tooagramfort commentedon Oct 11, 2021
cbrnr commentedon Oct 12, 2021
Ideally, we should only have to maintain
__repr__and just put its contents in a nice HTML table. I don't like that currently they contain different fields. I'm not even sure we need a description column for the fields when we could just use the keys (they should be self-explanatory and if not they are documented).cbrnr commentedon Oct 12, 2021
Maybe just something like this:
Which looks like:
[-]Synchronize `Info.__repr__()` and `Info._repr_html_()`[/-][+]Synchronize `__repr__()` and `_repr_html_()`[/+]cbrnr commentedon Oct 12, 2021
BTW, the same applies to
RawandEpochs. I think that the two reprs should contain the same pieces of information.hoechenberger commentedon Oct 12, 2021
@cbrnr In my current PR #9828 on adding ICA to Report, I also reworked
ICA.__repr__and addedICA._repr_html_. To reduce code duplication and improve consistency between the two, I took the following approach:mne-python/mne/preprocessing/ica.py
Lines 446 to 540 in 558c88a
I'm -1 on adding a
keycolumn as this will force us to do a 1-to-1 mapping between rows and keys or attributes, which I think is not practical:_html_repr_for many more objects than justInfoFitrow, I actually combine 3 fields, so it's impossible to have a 1-to-1 mapping:Also I'm adding info that's just not present in the object itself (i.e., is calculated), namely
Explained variancehoechenberger commentedon Oct 12, 2021
I want to add that my concern re 1-to-1 mapping can be disregarded if we're only talking about
Info.cbrnr commentedon Oct 13, 2021
I find it very strange to show different pieces of information depending on which backend is used. What exactly is the reason why showing exactly the same information is not feasible? The HTML repr is also just text which should easily fit in a terminal. This should not just synced for
Info, but also forRaw,Epochs, andICA(I don't think we have more).hoechenberger commentedon Oct 13, 2021
HTML repr allows us to present data in true tables (that we will make collapsible soon, too), while you'll typically want a very concise repr on the terminal. Data can also be styled beyond just a tabular alignment in HTML, while this stuff isn't easy without introducing new dependencies on the terminal (e.g., via rich)
Also I think that when adding some of the HTML reprs, we didn't want to / dare to change the existing
repr()output, but still wanted to take advantage of the features HTML offers.hoechenberger commentedon Oct 13, 2021
That said, +1 on ensuring they're more synchronous, but please don't make the HTML repr just an ugly HTML-ified copy of the text repr. It can do much better than that.
cbrnr commentedon Oct 13, 2021
I'm still -1 on using different reprs. I can already imagine the confusion when people notice that the output (repr) of an object in the interactive interpreter is widely different from inside a notebook. If you want to add nice HTML summaries I'd really prefer if that had its own dedicated method (e.g.
raw.print_html()or evenraw.print()). Changing the default repr is asking for trouble.25 remaining items
cbrnr commentedon Sep 13, 2022
I would like to res this issue because I think the current dissociation between the two reprs are still very confusing (at least to me). Specifically, when writing some tutorial in a notebook-like environment, people should see the exact same output whether they are in a REPL or a notebook. In general, I prefer the REPL, but I write my tutorial with Quarto (which uses Jupyter notebook under the hood), so when I tell people to run e.g.
I would like to see the REPL
__repr__()and not_repr_html_().Could we add a config option to disable all
_repr_html_()? I think we should because AFAIK it is not possible to change this behavior on the IPython side (https://stackoverflow.com/questions/73540055/how-can-i-force-repr-instead-of-repr-html-in-jupyter-notebooks).hoechenberger commentedon Sep 13, 2022
@cbrnr +1 for adding a configuration option if Jupyter doesn't support this. The default should IMHO still be to use HTML repr in a Jupyter environment.
cbrnr commentedon Sep 13, 2022
This would be great! And yes, HTML can remain the default for notebook envs.
Does anyone have an idea how to implement this technically? I briefly looked at how it's done in Scikit-learn, but couldn't really figure it out so I guess this will be a larger change.
I will also ask the IPython devs if they think this could be added on their end. Doesn't make a lot of sense that every package has to implement that.
hoechenberger commentedon Sep 13, 2022
Could you not simply do something like this:
?
cbrnr commentedon Sep 13, 2022
Unfortunately, this doesn't work (nothing gets printed). It seems like it's not just the returned value that's needed by the notebook.
hoechenberger commentedon Sep 13, 2022
hoechenberger commentedon Sep 13, 2022
@cbrnr I assume you'll have to escape the
<etc symbolshoechenberger commentedon Sep 13, 2022
Yep.
prints nothing.
But this works:
cbrnr commentedon Sep 13, 2022
Nice! So I guess we have a plan then! I will prepare a PR soon! Thanks a lot!
cbrnr commentedon Sep 13, 2022
Line breaks
\nshould not be escaped though – is this possible?cbrnr commentedon Sep 13, 2022
The font is also not a fixed-width font, which ideally would be nice to have as well...
cbrnr commentedon Sep 13, 2022
This should do it: