hdfdict helps h5py to dump and load python dictionaries
If you have a hierarchical data structure of numpy arrays in a dictionary for example, you can use this tool to save this dictionary into a h5py File() or Group() and load it again.
This tool just maps the hdf Groups to dict keys and the Datset to dict values.
Only types supported by h5py can be used.
The dicitonary-keys need to be strings until now.
A lazy loading option is activated per default. So big h5 files are not loaded at once. Instead a dataset gets only loaded if it is accessed from the LazyHdfDict instance.
Example
import hdfdict
import numpy as np
d = {
'a': np.random.randn(10),
'b': [1, 2, 3],
'c': 'Hallo',
'd': np.array(['a', 'b']).astype('S'),
'e': True,
'f': (True, False),
}
fname = 'test_hdfdict.h5'
hdfdict.dump(d, fname)
res = hdfdict.load(fname)
print(res)
Output:
{'a': <HDF5 dataset "a": shape (10,), type "<f8">, 'b': <HDF5 dataset "b": shape (3,), type "<i8">, 'c': <HDF5 dataset "c": shape (), type "|O">, 'd': <HDF5 dataset "d": shape (2,), type "|S1">, 'e': <HDF5 dataset "e": shape (), type "|b1">, 'f': <HDF5 dataset "f": shape (2,), type "|b1">}
This are all lazy loding fields in the result res.
Just call res.unlazy() or dict(res) to get all fields loaded.
If you only want to load specific fields, just use item access e.g. res['a'] so only field 'a' will be loaded from the file.
print(dict(res))`
Output:
{'a': array([-0.47666824, 0.11787749, 0.51405835, -1.49557787, -0.33617182, -0.22381693, 0.25966526, 0.58160661, 0.17019176, 1.3167669 ]), 'b': array([1, 2, 3]), 'c': 'Hallo', 'd': array([b'a', b'b'], dtype='|S1'), 'e': True, 'f': array([ True, False])}
Installation
pip install hdfdictpoetry install hdfdictgit clone https://github.com/SiggiGue/hdfdict.gitandpython hdfdict/setup.py install
Metadata
Release files for hdfdict 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hdfdict-0.3.1.tar.gz | 5.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hdfdict-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / hdfdict-0.3.1.tar.gz
| Download URL | hdfdict-0.3.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
916209f4751b6b1c99d9a2194233fa142353e170b8601e480d431add65960f85
|
|
BLAKE2b-256 checksum How to use checksums |
ed6e35198b32082cc8b9164b94d481fb08347abcca66441e3f0d09361a13d8e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.3 Linux/5.0.0-25-generic
|
Release files / hdfdict-0.3.1-py3-none-any.whl
| Download URL | hdfdict-0.3.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e875e4fefe767af9b23bf69b593683c2cbba7692e9baf4621333bdb50aecfa2b
|
|
BLAKE2b-256 checksum How to use checksums |
ab29bdd444399c839b24d837937d8ca255b1b95a3463e58c03abe04890b0717b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.17 CPython/3.7.3 Linux/5.0.0-25-generic
|