Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datajoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import os

__author__ = "Dimitri Yatsenko, Edgar Y. Walker, and Fabian Sinz at Baylor College of Medicine"
__version__ = "0.4.2"
__date__ = "Nov 27, 2016"
__version__ = "0.4.3"
__date__ = "Nov 29, 2016"
__all__ = ['__author__', '__version__',
'config', 'conn', 'kill', 'BaseRelation',
'Connection', 'Heading', 'FreeRelation', 'Not', 'schema',
Expand Down
35 changes: 30 additions & 5 deletions datajoint/relational_operand.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,25 +360,50 @@ def preview(self):
' '.join([templates[f] % ('*'+f if f in rel.primary_key else f) for f in columns]) + '\n' +
' '.join(['+' + '-' * (widths[column] - 2) + '+' for column in columns]) + '\n' +
'\n'.join(' '.join(templates[f] % tup[f] for f in columns) for tup in tuples) +
('\n...\n' if len(rel) > limit else '\n') +
('\n ...\n' if len(rel) > limit else '\n') +
' (%d tuples)\n' % len(rel))

def _repr_html_(self):
rel = self.proj(*self.heading.non_blobs,
**dict(zip_longest(self.heading.blobs, [], fillvalue="'=BLOB='"))) # replace blobs with =BLOB=
info = self.heading.table_info
count = len(rel)
return """ {title}

css = """
<style type="text/css">
.Relation{
border-collapse:collapse;
}
.Relation th{
background: #A0A0A0; color: #ffffff; padding:4px; border:#f0e0e0 1px solid;
font-weight: normal; font-family: monospace; font-size: 75%;
}
.Relation td{
padding:4px; border:#f0e0e0 1px solid; font-size:75%;
}
.Relation tr:nth-child(odd){
background: #ffffff;
}
.Relation tr:nth-child(even){
background: #f3f1ff;
}
</style>
"""

return """
{css}
{title}
<div style="max-height:1000px;max-width:1500px;overflow:auto;">
<table border="1" class="dataframe">
<table border="1" class="Relation">
<thead> <tr style="text-align: right;"> <th> {head} </th> </tr> </thead>
<tbody> <tr> {body} </tr> </tbody>
</table>
{ellipsis}
<p>{count} tuples</p></div>
""".format(
title="" if info is None else "<h3>%s</h3>" % info['comment'],
head='</th><th>'.join("<em>" + c + "</em>" if c in self.primary_key else c
css=css,
title="" if info is None else "<b>%s</b>" % info['comment'],
head='</th><th>'.join('<b><font color="black">' + c + "</font></b>" if c in self.primary_key else c
for c in rel.heading.names),
ellipsis='<p>...</p>' if count > config['display.limit'] else '',
body='</tr><tr>'.join(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,4 @@ def test_table_size(self):
assert_true(self.experiment.size_on_disk > 100)

def test_repr_html(self):
assert_true(self.ephys._repr_html_().strip().startswith("<h3>"))
assert_true(self.ephys._repr_html_().strip().startswith("<style"))