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

Added pretty representation of ProjectSchema for IPython #324

Merged
merged 8 commits into from
Apr 13, 2020

Conversation

vishav1771
Copy link
Contributor

@vishav1771 vishav1771 commented Apr 10, 2020

Description

Added _repr_html_ method in ProjectSchema

Motivation and Context

Resolves #314

Types of Changes

  • Documentation update
  • Bug fix
  • New feature
  • Breaking change1

1The change breaks (or has the potential to break) existing functionality.

Checklist:

If necessary:

  • I have updated the API documentation as part of the package doc-strings.
  • I have created a separate pull request to update the framework documentation on signac-docs and linked it here.
  • I have updated the changelog and added all related issue and pull request numbers for future reference (if applicable). See example below.

Example for a changelog entry: Fix issue with launching rockets to the moon (#101, #212).

@vishav1771 vishav1771 requested review from a team as code owners April 10, 2020 11:20
@codecov
Copy link

codecov bot commented Apr 10, 2020

Codecov Report

Merging #324 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #324      +/-   ##
==========================================
+ Coverage   76.19%   76.21%   +0.01%     
==========================================
  Files          43       43              
  Lines        7078     7083       +5     
==========================================
+ Hits         5393     5398       +5     
  Misses       1685     1685              
Impacted Files Coverage Δ
signac/contrib/schema.py 97.69% <100.00%> (+0.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update beefdf8...9a6c767. Read the comment docs.

@@ -136,6 +138,15 @@ def __str__(self):
def __repr__(self):
return "{}(<len={}>)".format(type(self).__name__, len(self))

def _repr_html_(self):
html = "{<br>"
Copy link
Member

@b-butler b-butler Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still include the type name for the project before the opening bracket. pandas does not, but in this case given it will look like a dictionary otherwise, so I think we should.

Copy link
Member

@b-butler b-butler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I have one comment to address.

Copy link
Member

@bdice bdice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishav1771 I made a suggested code snippet, and I applied it (it's somewhat simpler and uses existing formatting logic that we already trust). For testing, I added a few lines to the class TestProjectRepresentation in test_project.py. I think that will make this PR ready to merge with one other approval (@b-butler?). This is a small convenience feature so I'm fine with fast-tracking it and merging quickly.

Comment on lines 142 to 148
html = "{<br>"
for key in sorted(self._schema):
values = self._schema[key]
if values:
html += "<pre> '{}': '{}',</pre>".format(key, self._fmt_values(values, 5))
html += "}"
return html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Brandon has a good recommendation above. @vishav1771 It looks like this PR is re-creating the same formatting logic that is in __str__. I suggest the following code snippet -- I'm happy with this output (screenshot below).

Suggested change
html = "{<br>"
for key in sorted(self._schema):
values = self._schema[key]
if values:
html += "<pre> '{}': '{}',</pre>".format(key, self._fmt_values(values, 5))
html += "}"
return html
import html
html_repr = "<strong>" + html.escape(repr(self)) + "</strong>"
html_repr += "<pre>" + str(self) + "</pre>"
return html_repr

image

@bdice
Copy link
Member

bdice commented Apr 13, 2020

@vishav1771 One more thing - you might want to update your fork's master branch so that it's up-to-date with the glotzerlab:master branch. I think it might be somewhat behind.

@bdice
Copy link
Member

bdice commented Apr 13, 2020

I also reverted the changes to _fmt_values because those changes are no longer necessary with my changes to _repr_html_.

@vyasr vyasr requested review from a team and Charlottez112 and removed request for a team April 13, 2020 16:24
Copy link
Member

@b-butler b-butler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bdice bdice merged commit 39e3f2e into glotzerlab:master Apr 13, 2020
@bdice bdice added this to the v1.5.0 milestone Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

project.detect_schema() should have a pretty representation in IPython
4 participants