<commit_before>'''hdf - HDF5 wrappers and utilities'''

from typing import (Any, Sequence, List, Mapping,
                    Callable, Union, Optional)

import h5py
import numpy as np
import pandas as pd

from .rw import read_plumed_fields

__all__ = ['plumed_to_h5', 'plumed_to_hdf', 'hdf_to_dataframe']


def plumed_to_hdf(
        files: Union[List[str], str],
        hdf_file: str,
        keys: Union[List[str], str],
        field_map: Optional[Mapping[str, str]]=None,
        columnwise: bool=False,
) -> None:
    '''
    Read PLUMED files and dump to HDF5.

    Parameters
    ----------
    files : Files generated by PLUMED.
    hdf_file : Path to HDF file.
    keys : Keys to be used for top-level HDF groups.
    field_map : Mapping to replace potentially bad names for fields.
    columnwise : Operate on columns instead of whole files,
        this is easier on memory, but far slower.

    '''

    # Check input
    if isinstance(files, list):
        files = [files]
    if isinstance(keys, list):
        keys = [keys]
    if len(keys) != len(files):
        raise ValueError(
            'You must supply the same number of callables as files!'
        )

    with h5py.File(hdf_file, 'w') as store:

        for key, file in zip(keys, files):

            fields = read_plumed_fields(file)
<commit_msg>hdf: fixed bug in plumed_to_hdf<commit_after>'''hdf - HDF5 wrappers and utilities'''

from typing import (Any, Sequence, List, Mapping,
                    Callable, Union, Optional)

import h5py
import numpy as np
import pandas as pd

from .rw import read_plumed_fields

__all__ = ['plumed_to_h5', 'plumed_to_hdf', 'hdf_to_dataframe']


def plumed_to_hdf(
        files: Union[List[str], str],
        hdf_file: str,
        keys: Union[List[str], str],
        field_map: Optional[Mapping[str, str]]=None,
        columnwise: bool=False,
) -> None:
    '''
    Read PLUMED files and dump to HDF5.

    Parameters
    ----------
    files : Files generated by PLUMED.
    hdf_file : Path to HDF file.
    keys : Keys to be used for top-level HDF groups.
    field_map : Mapping to replace potentially bad names for fields.
    columnwise : Operate on columns instead of whole files,
        this is easier on memory, but far slower.

    '''

    # Check input
    if not isinstance(files, list):
        files = [files]
    if not isinstance(keys, list):
        keys = [keys]
    if len(keys) != len(files):
        raise ValueError(
            'You must supply the same number of callables as files!'
        )

    with h5py.File(hdf_file, 'w') as store:

        for key, file in zip(keys, files):

            fields = read_plumed_fields(file)

{'fraction_non_alphanumeric': 0.10044809559372667, 'fraction_numerical': 0.0037341299477221808, 'mean_word_length': 2.456774193548387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1832851', 'n_tokens_mistral': 853, 'n_tokens_neox': 830, 'n_words': 288}