-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
html representation for jupyter notebooks #1217
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have a second round of comments after this first one. Also in regards to CI errors let us know if you need help learning how to get to them, or understand what they are saying.
Can you add a screenshot as well showing what these changes do in the notebook? I thought the xarray repr was already in html in jupyter if we set the xarray option. What is this adding on top of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also update cookbook and quickstart notebooks to show the html goodness :)
@canyon289 Yes the xarray's repr is in html if we set the option. This PR is making the whole inferenceData object dynamic. The result can be seen in this jupyter notebook: https://nbviewer.jupyter.org/github/percygautam/arviz-examples/blob/master/HTML%20repr.ipynb |
arviz/utils.py
Outdated
</div> | ||
""" | ||
element_template = """ | ||
<ul class="xr-sections"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the vertical spacing between groups is very large. I think this could be due to ul
being part of the element template as this is defining a different list for each group. Can you try moving it to the html template so that we have a single list (only one ul
defined in html template) and the groups are then elements of this single list (one li
per group)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ul
/li
change is also marked as resolved but it is not and again I have a vague memory of seeing the ul
moved to html instead of element template :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Havent had time to rereview but don't want to block if this PR is ready to go. Deferring judgement to whoever gets to it before me
LGTM, we can merge after updating a couple notebooks. |
I am going to request tests before merge. IMO all code should be tested if it can, and this is no exception :). I would add a test that calls I would also add a tests the correct repr is returned without an explicit call. I assume this will require some mocking and to "trick" the non jupyter notebook test to provide the html repr. As is such still requesting some changes :) |
arviz/utils.py
Outdated
|
||
|
||
class HtmlTemplate: | ||
"""Contains html templates.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expand docstring. Contains html templates for what?
Would change this to something along the lines of contains html templates for InferenceData repr
@percygautam this is already looking great and youre on the right track. Hope you dont mind my additional comments :) |
I have added the basic test. How do I add the second test? I looked through but couldn't find the way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pystan refitting and numba notebooks have no inferencedata so there is no need to rerun them
Actually I did revert some commits as I have forgot to gitignore the cache of notebooks and pushed them. I'll check and make all the changes again. |
Codecov Report
@@ Coverage Diff @@
## master #1217 +/- ##
==========================================
- Coverage 93.09% 93.09% -0.01%
==========================================
Files 95 94 -1
Lines 9591 9525 -66
==========================================
- Hits 8929 8867 -62
+ Misses 662 658 -4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still needs more tests, Please add them. Approving so I don't block you
msg = "Inference data with groups:\n\t> {options}".format( | ||
options="\n\t> ".join(self._groups) | ||
) | ||
if self._groups_warmup: | ||
msg += "\n\nWarmup iterations saved ({}*).".format(WARMUP_TAG) | ||
return msg | ||
|
||
def _repr_html_(self): | ||
"""Make html representation of InferenceData object.""" | ||
display_style = OPTIONS["display_style"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to request tests before merge. IMO all code should be tested if it can, and this is no exception :). I would add a test that calls
_repr_html_
directly and tests that the html string is returned.
I would also add a tests the correct repr is returned without an explicit call. I assume this will require some mocking and to "trick" the non jupyter notebook test to provide the html repr.I have added the basic test. How do I add the second test? I looked through but couldn't find the way.
This is going to be fun one. Making tests is sometimes a puzzle and harder than the actual programming itself, but important if you want you feature to be stable and not broken by any others.
In the test you'll have to monkeypatch OPTIONS
to so when the test executes the value is text
to test that this if condition works. Just being up front here it's going to be hard and confusing, but youre going to learn a lot more about python.
I don't want to block this whole PR for that one thing though. We can merge but I really would like you to add this test in a followup PR. At a minimum create an issue so we can track
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will not be necessary to monekypatch because the display style option is already customizable similarly to an rcParam. We can start the test by setting the display_style
to text
/html
, make sure the correct repr is returned and then finish the test by going back to the original displaystyle (much like your original implementation of the repr @percygautam).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its typically bad practice to have tests rely on global state like rcparam although in this case lets just do it cause monkeypatching would be annoying :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am okay with both options. We can currently implement the test using rcParams, and create the issue to track the monkeypatch test and merge this PR. I will implement the test later.
The html_repr
really facilitates to check other methods that I am adding, so it'll be better to merge this one as soon as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with merging as soon as possible! Seems like youre only a couple linting errors away :)
Add changelog and this one should be good to go |
@percygautam can you rebase and rerun notebook? |
Description
This PR implements the html representation for arviz.InferenceData object in jupyter notebooks. Related to discussion in #1066.
Checklist