Column datatypes#
Helpers for the two datatypes HDF5 does not hand to NumPy directly: the fixed-length UTF-8 string and the H5Col boolean enumeration. The column datatypes chapter explains when to reach for each.
Fixed-length strings#
- class h5col.FixedString(nbytes: int, encoding: str = 'utf-8')[source]#
A fixed-length HDF5 string datatype of
nbytesbytes.- Parameters:
- Raises:
SchemaError – If nbytes is not a positive integer, or encoding is unsupported.
- encode_scalar(value: object, *, index: int | None = None) bytes[source]#
Encode a single value to bytes, enforcing the byte budget.
Raises
OversizedStringErrorif the encoding exceedsnbytes.
- encode(values: Any) NDArray[bytes_][source]#
Encode an array-like of strings to a
|S{nbytes}array.No value is ever truncated: the first over-budget value raises
OversizedStringError.
- decode_scalar(raw: bytes | bytearray | bytes_) str[source]#
Decode a single stored value to
str(trailing NULs stripped).
- decode(values: Any) NDArray[object_][source]#
Decode an array-like of stored bytes to an object array of
str.
- classmethod from_dtype(dtype: Any) FixedString[source]#
Build a
FixedStringfrom an existing fixed-length string dtype.- Raises:
SchemaError – If dtype is not an HDF5 string dtype, or is a variable-length (not fixed-length) string dtype.
Booleans#
- h5col.bool_dtype() dtype[source]#
Return the H5Col boolean dtype (enum over little-endian signed int8).
On little-endian platforms the
<i1base is byte-identical toH5T_STD_I8LE, which is what H5Col mandates.
- h5col.is_bool_dtype(dtype: Any) bool[source]#
Return True if dtype is an acceptable H5Col boolean datatype.
Applies the consumer-lenient rule: any one-byte integer enumeration, of either signedness, whose members are exactly
FALSE= 0 andTRUE= 1. Also accepts NumPybool: h5py normalizes its FALSE/TRUE-over-int8 enum (which is the H5Col boolean datatype on disk) back toboolon read.
- h5col.encode_bool(values: Any) NDArray[int8][source]#
Encode a boolean/0-1 array-like to an
int8array of codes.Raises
SchemaErrorif an integer input holds a value other than 0 or 1 (H5Col boolean columns may hold only those two codes).
- h5col.decode_bool(values: Any) NDArray[bool][source]#
Decode stored integer codes to a NumPy boolean array.
Every code must be 0 (FALSE) or 1 (TRUE). A code outside that domain is a non-conformant boolean value; H5Col forbids interpreting it as either FALSE or TRUE, so this raises
ConformanceErrorinstead of silently coercing (NumPy maps every nonzero code toTrue).