forked from dask/distributed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HTML reprs for Client.who_has and Client.has_what (dask#4853)
- Loading branch information
1 parent
26a1da0
commit 2e01873
Showing
2 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""This file contains custom objects. | ||
These are mostly regular objects with more useful _repr_ and _repr_html_ methods.""" | ||
|
||
|
||
class HasWhat(dict): | ||
"""A dictionary of all workers and which keys that worker has.""" | ||
|
||
def _repr_html_(self): | ||
rows = "" | ||
|
||
for worker, keys in sorted(self.items()): | ||
summary = "" | ||
for key in keys: | ||
summary += f"""<tr><td>{key}</td></tr>""" | ||
|
||
rows += f"""<tr> | ||
<td>{worker}</td> | ||
<td>{len(keys)}</td> | ||
<td> | ||
<details> | ||
<summary style='display:list-item'>Expand</summary> | ||
<table> | ||
{summary} | ||
</table> | ||
</details> | ||
</td> | ||
</tr>""" | ||
|
||
output = f""" | ||
<table> | ||
<tr> | ||
<th>Worker</th> | ||
<th>Key count</th> | ||
<th>Key list</th> | ||
</tr> | ||
{rows} | ||
</table> | ||
""" | ||
|
||
return output | ||
|
||
|
||
class WhoHas(dict): | ||
"""A dictionary of all keys and which workers have that key.""" | ||
|
||
def _repr_html_(self): | ||
rows = "" | ||
|
||
for title, keys in sorted(self.items()): | ||
rows += f"""<tr> | ||
<td>{title}</td> | ||
<td>{len(keys)}</td> | ||
<td>{", ".join(keys)}</td> | ||
</tr>""" | ||
|
||
output = f""" | ||
<table> | ||
<tr> | ||
<th>Key</th> | ||
<th>Copies</th> | ||
<th>Workers</th> | ||
</tr> | ||
{rows} | ||
</table> | ||
""" | ||
|
||
return output |