-
-
Notifications
You must be signed in to change notification settings - Fork 330
Add tree #140
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
Add tree #140
Changes from all commits
673ec6b
44fdd52
b242d53
830a52d
f9e8435
1365a80
1975711
f709e9e
0037f2f
67e2407
58486be
0f67052
f9170cd
f5ce2ee
590f98d
d9682de
7b9a6ae
b7a5fd9
8da154a
3a4c65c
d3d06db
d09caa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import zarr\n", | ||
"\n", | ||
"# Python 2/3 trick\n", | ||
"try:\n", | ||
" unicode\n", | ||
"except NameError:\n", | ||
" unicode = str" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"g1 = zarr.group()\n", | ||
"g3 = g1.create_group('bar')\n", | ||
"g3.create_group('baz')\n", | ||
"g5 = g3.create_group('quux')\n", | ||
"g5.create_dataset('baz', shape=100, chunks=10)\n", | ||
"g7 = g3.create_group('zoo')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"/\n", | ||
" +-- bar\n", | ||
" +-- baz\n", | ||
" +-- quux\n", | ||
" | +-- baz[...]\n", | ||
" +-- zoo\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(bytes(g1.tree()).decode())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"bar\n", | ||
" ├── baz\n", | ||
" ├── quux\n", | ||
" │ └── baz[...]\n", | ||
" └── zoo\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(unicode(g3.tree()))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<style type=\"text/css\">\n", | ||
"div.zarr-tree {\n", | ||
" font-family: Courier, monospace;\n", | ||
" font-size: 11pt;\n", | ||
" font-style: normal;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree ul,\n", | ||
"div.zarr-tree li,\n", | ||
"div.zarr-tree li > div {\n", | ||
" display: block;\n", | ||
" position: relative;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree ul,\n", | ||
"div.zarr-tree li {\n", | ||
" list-style-type: none;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree li {\n", | ||
" border-left: 2px solid #000;\n", | ||
" margin-left: 1em;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree li > div {\n", | ||
" padding-left: 1.3em;\n", | ||
" padding-top: 0.225em;\n", | ||
" padding-bottom: 0.225em;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree li > div::before {\n", | ||
" content: '';\n", | ||
" position: absolute;\n", | ||
" top: 0;\n", | ||
" left: -2px;\n", | ||
" bottom: 50%;\n", | ||
" width: 1.2em;\n", | ||
" border-left: 2px solid #000;\n", | ||
" border-bottom: 2px solid #000;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree > ul > li:first-child > div {\n", | ||
" padding-left: 4%;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree > ul > li:first-child > div::before {\n", | ||
" border: 0 none transparent;\n", | ||
"}\n", | ||
"\n", | ||
"div.zarr-tree ul > li:last-child {\n", | ||
" border-left: 2px solid transparent;\n", | ||
"}\n", | ||
"</style>\n", | ||
"\n", | ||
"<div class=\"zarr-tree\">\n", | ||
"<ul>\n", | ||
" <li><div>/</div>\n", | ||
" <ul>\n", | ||
" <li><div>bar</div>\n", | ||
" <ul>\n", | ||
" <li><div>baz</div></li>\n", | ||
" <li><div>quux</div>\n", | ||
" <ul>\n", | ||
" <li><div>baz[...]</div></li>\n", | ||
" </ul>\n", | ||
" </li>\n", | ||
" <li><div>zoo</div></li>\n", | ||
" </ul>\n", | ||
" </li>\n", | ||
" </ul>\n", | ||
" </li>\n", | ||
"</ul>\n", | ||
"</div>\n" | ||
], | ||
"text/plain": [ | ||
"/\n", | ||
" └── bar\n", | ||
" ├── baz\n", | ||
" ├── quux\n", | ||
" │ └── baz[...]\n", | ||
" └── zoo" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"g1.tree()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
asciitree | ||
nose | ||
numpy | ||
fasteners | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
appdirs==1.4.3 | ||
args==0.1.0 | ||
asciitree==0.3.3 | ||
certifi==2017.7.27.1 | ||
chardet==3.0.4 | ||
clint==0.5.1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
asciitree | ||
setuptools | ||
setuptools_scm | ||
sphinx | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,17 @@ | |
from collections import MutableMapping | ||
from itertools import islice | ||
|
||
|
||
import numpy as np | ||
|
||
|
||
from zarr.compat import PY2 | ||
from zarr.attrs import Attributes | ||
from zarr.core import Array | ||
from zarr.storage import (contains_array, contains_group, init_group, DictStore, group_meta_key, | ||
attrs_key, listdir, rmdir) | ||
from zarr.creation import (array, create, empty, zeros, ones, full, empty_like, zeros_like, | ||
ones_like, full_like, normalize_store_arg) | ||
from zarr.util import (normalize_storage_path, normalize_shape, InfoReporter, | ||
from zarr.storage import (contains_array, contains_group, init_group, | ||
DictStore, group_meta_key, attrs_key, listdir, rmdir) | ||
from zarr.creation import (array, create, empty, zeros, ones, full, | ||
empty_like, zeros_like, ones_like, full_like, normalize_store_arg) | ||
from zarr.util import (normalize_storage_path, normalize_shape, InfoReporter, TreeViewer, | ||
is_valid_python_name, instance_dir) | ||
from zarr.errors import err_contains_array, err_contains_group, err_group_not_found, err_read_only | ||
from zarr.meta import decode_group_metadata | ||
|
@@ -62,6 +61,7 @@ class Group(MutableMapping): | |
visitkeys | ||
visitvalues | ||
visititems | ||
tree | ||
create_group | ||
require_group | ||
create_groups | ||
|
@@ -546,6 +546,34 @@ def visititems(self, func): | |
base_len = len(self.name) | ||
return self.visitvalues(lambda o: func(o.name[base_len:].lstrip("/"), o)) | ||
|
||
def tree(self): | ||
"""Provide a ``print``-able display of the hierarchy. | ||
|
||
Examples | ||
-------- | ||
>>> import zarr | ||
>>> g1 = zarr.group() | ||
>>> g2 = g1.create_group('foo') | ||
>>> g3 = g1.create_group('bar') | ||
>>> g4 = g3.create_group('baz') | ||
>>> g5 = g3.create_group('quux') | ||
>>> d1 = g5.create_dataset('baz', shape=100, chunks=10) | ||
>>> print(g1.tree()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest just:
I.e., no need to call print(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a strong thought by any means, but |
||
/ | ||
├── bar | ||
│ ├── baz | ||
│ └── quux | ||
│ └── baz[...] | ||
└── foo | ||
>>> print(g3.tree()) | ||
bar | ||
├── baz | ||
└── quux | ||
└── baz[...] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opted to try displaying the datasets like this. Please let me know what you think. |
||
""" | ||
|
||
return TreeViewer(self) | ||
|
||
def _write_op(self, f, *args, **kwargs): | ||
|
||
# guard condition | ||
|
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.
Consider adding a
depth
argument here which defaults toNone
(i.e., render the whole subtree) but can be an integer which would limit the tree depth - useful where you only want to view a few levels down, but whole tree might be unwieldy.