This release is a pre-release and may not be stable for production use.
Hierarchical Data Table (HDTable)
This Python package generates grid tables that are reStructuredText compliant from a data source and column specifications. An example of a rendered reStructuredText grid table is:
Student # |
Class # |
Class Name |
Project Name |
Teacher # |
Teacher Name |
Class Mascot |
|---|---|---|---|---|---|---|
1 |
1 |
math |
science fair |
1 |
daniel |
wombat |
2 |
chinese |
yearbook |
||||
3 |
computer science |
robotics |
||||
2 |
ethan |
|||||
4 |
physics |
esport |
||||
2 |
1 |
math |
robotics |
|||
3 |
frank |
|||||
2 |
chemistry |
|||||
3 |
physics |
|||||
4 |
greg |
|||||
3 |
1 |
english |
N/A |
|||
2 |
chinese |
|||||
5 |
hank |
|||||
3 |
chemistry |
|||||
4 |
N/A |
N/A |
N/A |
The source for this table can be generated by HDTable with
import os
import yaml
from hdtable.hdtable import Hdtable
data_source_file = os.path.join("tests", "test_data.yml")
specs_file = os.path.join("tests", "specs", "sample.yml")
with open(data_source_file, "r") as f:
d = yaml.safe_load(f)
with open(specs_file, "r") as f:
specs = yaml.safe_load(f)
hdtable = Hdtable(d, specs)
print(hdtable)
which produces:
+-----------+---------+------------------+--------------+-----------+--------------+--------------+ | Student # | Class # | Class Name | Project Name | Teacher # | Teacher Name | Class Mascot | +===========+=========+==================+==============+===========+==============+==============+ | 1 | 1 | math | science fair | 1 | daniel | wombat | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+------------------+--------------+ | | | | | 2 | chinese | yearbook | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+------------------+--------------+ | | | | | 3 | computer science | robotics | | | | | | | | +-----------+--------------+ | | | | | | 2 | ethan | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+------------------+--------------+ | | | | | 4 | physics | esport | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------+---------+------------------+--------------+ | | | | 2 | 1 | math | robotics | | | | | | | | | | | | | | | | | | | | | | | | +-----------+--------------+ | | | | | | 3 | frank | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+------------------+ | | | | | | 2 | chemistry | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+------------------+ | | | | | | 3 | physics | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------+--------------+ | | | | | | 4 | greg | | | | | | | | | | | | | | | | | | +-----------+---------+------------------+--------------+ | | | | 3 | 1 | english | N/A | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +---------+------------------+ | | | | | | 2 | chinese | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------+--------------+ | | | | | | 5 | hank | | | +---------+------------------+ | | | | | | 3 | chemistry | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------+---------+------------------+--------------+ | | | | 4 | N/A | N/A | N/A | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +-----------+---------+------------------+--------------+-----------+--------------+--------------+
Install
$ pip install hdtable
Explanation of columns
The element of the specs specify the root object, you can use a dictionary with an empty keys array for HDTable to use the entire provided data object. This “column 0” is invisible and will not be printed.
Each consecutive element in the specs list defines a column in the table, beginning with column 1. Each column respresents a domain of data. In the sample table, the domain of the first column is all the students in the class, which is a list. Each row in column 1 is the index of that student beginning with 1. The domain of the second column is each student’s classes they are taking. No the student is not taking any class, the entry shows “N/A”. Column 3 represents the same data domain as column 2, which is the classes each student is taking, but it is in the form of string instead of index.
The data domain of column 4 inherits not from column 1 but from the invisible column 0 (the root column). It lists all the teachers for that class in the form of indices.
Data Source
The data source can be a dictionary or list. All example data given here are in YAML format for readability. An example of a data source that contains information a class is in tests/example_data.yml.
Column Specifications
Column specifications, or column specs, define the domain of data each column shows. Each spec is a Python dictionary that must contain a keys entry, and optionally, parent,``dtype``, and header entries. The column specs that produced the sample table above is in tests/specs/sample.yml:
- keys: []
- keys: ["students"]
dtype: index
header: "Student #"
- keys: ["classes"]
dtype: index
parent: 1
header: "Class #"
- keys: []
parent: 2
header: Class Name
- keys: ["projects"]
parent: 1
dtype: key
header: Project Name
- keys: ["teachers"]
dtype: index
parent: 0
header: "Teacher #"
- keys: []
parent: 5
header: Teacher Name
- keys: ["mascot"]
header: Class Mascot
Parameter |
Required |
Default |
Function |
|---|---|---|---|
keys |
Yes |
N/A |
The dict keys used to retrieve data. A list of strings. Can be empty. |
parent |
No |
0 (root) |
The parent column from which the keys will be used to retrieve this column’s data |
dtype |
No |
string |
The data type of that column. Can be “index”, “key”, or “string”. |
header |
No |
guessed from keys |
The displayed header for that column |
dtype
dtype defines the data format of a column. There are currently 3 possible types:
string: try to convert the object to a string
index: try to index the object if it is a dictionary or list.
key: displays the keys if the object is a dictionary.
Anatomy
+--------+-------+
| col 1 | col 2 | <─┬─ row height of ``col 2``
+========+=======+ <─┘
row height of ``xyz`` ─┬─> | xyz | abc |
├─> | +-------+
├─> | | def | <─── row 5 starting row of ``def``
└─> +--------+-------+
││││││││
└┴┴┼┴┴┴┘
width of column 0
Metadata
Release files for hdtable 0.1a5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hdtable-0.1a5.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hdtable-0.1a5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.5 kB
Release files / hdtable-0.1a5.tar.gz
| Download URL | hdtable-0.1a5.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
712677aa63db237ef69cf47e84e52ee4ebf8b6bce1ef25a9d01fb79c46d7a2b9
|
|
BLAKE2b-256 checksum How to use checksums |
58eebae07aef7a0e64db2568e9e313f53378911f29c6a2d24c9bcfe55d631401
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|
Release files / hdtable-0.1a5-py3-none-any.whl
| Download URL | hdtable-0.1a5-py3-none-any.whl |
|---|---|
| Size | 21.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4541a2e1cf715788c0fc24e533065357983473e7b9dc0ebefa81c1c20a14812a
|
|
BLAKE2b-256 checksum How to use checksums |
f9d5d4e5d366d7cb772704aa137b1ce6644e79ce3c9a941e3a68d12b68b5369c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|