Beispiel #1
0
def _make_float_vlarray(h5file: tables.File, name: str,
                        attribute: np.ndarray) -> None:
    vlarray = h5file.create_vlarray(h5file.root,
                                    name=name,
                                    atom=tables.Float64Atom(shape=()))
    for a in attribute:
        vlarray.append(a)
Beispiel #2
0
def _make_str_vlarray(h5file: tables.File, name: str,
                      attribute: List[str]) -> None:
    vlarray = h5file.create_vlarray(h5file.root,
                                    name=name,
                                    atom=tables.VLStringAtom())
    for a in attribute:
        vlarray.append(a)
Beispiel #3
0
def _add_vlarray(
    file: tables.File,
    where: tables.group,
    name: str,
    to_store: List[Union[str, HomList]],
) -> None:
    """
    Adds a ragged array to a tables file. Each row in the array is
    populated by an element of `to_store`, which can contain either strings or
    lists of any of the types supported by PyTables. This includes
    floats, integers and other scalar data types.

    Parameters
    ----------
    file : tables.File
    where : tables.Group
    name : str
    to_store : list of either str or lists of scalars
    """
    if to_store:
        if isinstance(to_store[0], str):
            to_store = [s.encode("utf-8") for s in to_store]
            atom = tables.VLStringAtom()
        else:
            to_store = [np.array(ll) for ll in to_store]
            atom = tables.Atom.from_dtype(to_store[0].dtype)
    else:
        atom = tables.StringAtom(itemsize=1)

    vla = file.create_vlarray(
        where,
        name,
        atom=atom,
        filters=compression_filter,
        expectedrows=len(to_store),
    )
    for s in to_store:
        vla.append(s)