Abstract base classes for making h5py-like objects.
Project description
h5py_like
Some base classes and helper functions for an approximately h5py-like API in python 3.7+.
Use case
You have a library which reads/writes contiguous regions of chunked numeric arrays, and want to make it behave somewhat like h5py.
Not supported
- Empty and scalar data spaces
- Logical indexing
- Broadcasting (other than scalar)
- Dimension scales
Differences from h5py
- Access modes are converted to enums, although they are largely compatible with the
strforms"x"is preferred over"w-"for exclusive creation
Usage
See the trivial HDF5 implementation in the tests package.
Create your own Dataset, Group, File, and AttributeManager classes,
implementing their abstract methods.
Because Files should subclass your Group, the base class here is a mixin.
It should come before the Group in the MRO.
Methods containing write operations should be given the @mutation decorator.
This checks their mode attribute and raises an error if it is readonly.
from h5py_like import DatasetBase, GroupBase, AttributeManagerBase, FileMixin, mutation
class MyDataset(DatasetBase):
# ... implement abstract methods
@mutation
def __setitem__(self, idx, val):
...
class MyGroup(GroupBase):
# ... implement abstract methods
pass
class MyFile(FileMixin, MyGroup):
# ... implement abstract methods
pass
class MyAttributeManager(AttributeManagerBase):
# ... implement abstract methods
pass
Helpers
h5py_like.shape_utils contains a variety of helper functions,
to simulate numpy's flexibility.
Testing
A suite of tests for basic h5py-like functionality is included.
To use it, you must be using pytest, and define a fixture which yields an instance of your File implementation.
Then you just need to subclass the provided abstract test classes:
conftest.py
import pytest
@pytest.fixture
def file_():
yield MyFile("my_name")
test_implementation.py
from h5py_like.test_utils import FileTestBase, GroupTestBase, DatasetTestBase, ModeTestBase
# concrete class names must start with Test
class TestFile(FileTestBase):
pass
class TestGroup(GroupTestBase):
pass
class TestDataset(DatasetTestBase):
pass
class TestMode(ModeTestBase):
def factory(self, mode):
# Instantiate your File object in the given mode in a way which is repeatable within a method.
return MyFile(mode)
If your dataset implementation supports chunking and threading, use the ThreadedDatasetTestBase base class instead.
The provided base classes test some of the expected functionality, even if you don't write any methods in your test classes. You can add more tests if you like, or override those you want to change, or decorate any you to skip or xfail.
The GroupTestBase provides a group_name attribute and a self.group(parent) method for creating a group of that name.
The DatasetTestBase provides dataset_ name, shape, and dtype, and a self.dataset(parent) method for making that dataset.
Notes
If you only want to implement part of the h5py-like API, just raise NotImplementedError().
Then your classes are being explicit about what they do and don't support.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file h5py_like-0.5.1.tar.gz.
File metadata
- Download URL: h5py_like-0.5.1.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5505dbdac0edb595a5c46365c4585a93ec6b3b324b6340ad03f1404599190e2
|
|
| MD5 |
337f76029b8a386e75f2e63e5ae7d60a
|
|
| BLAKE2b-256 |
f8c3f10b6aa1f7c03daea0062a57bce5d341fd83193c9de3be2f542933272602
|
File details
Details for the file h5py_like-0.5.1-py3-none-any.whl.
File metadata
- Download URL: h5py_like-0.5.1-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68c485b9a44a92474717877292f1ddeca05a74638e7ba5f1f473d8ca67a708d2
|
|
| MD5 |
9a48fcdb5dae4eed4fdf524443fa2e1e
|
|
| BLAKE2b-256 |
1e179377f94189e892e46778e6e8f3783a682e12de63a8947a98df5d53e9dcc2
|