<commit_before>

import h5py
import numpy


class File:
    def __init__(self, filename, access='r'):
        self.filename = filename
        self.access = access
        self.f = h5py.File(self.filename, self.access)

    def save_attributes(self, attributes):
        for key, value in attributes.items():
            self.f.attrs[key] = value

    def save_adc(self, name, bins, counts, energies):
        adc = self.f.create_group(name)
        adc.attrs['bins'] = bins
        adc.create_dataset('counts', data=counts, shape=(bins,))
        adc.create_dataset('energies', data=energies, shape=(bins,))

    def read_attributes(self):
        return {key: value for key, value in self.f.attrs.items()}

    def read_adc(self, name):
        adc_group = self.f[name]
        bins = adc_group.attrs['bins']
        counts = numpy.array(adc_group['counts'])
        energies = numpy.array(adc_group['energies'])
        return bins, counts, energies

    def close(self):
        self.f.close()
<commit_msg>Possibly switching it back to context manager?<commit_after>

import h5py
import numpy


class File:
    def __init__(self, filename, access='r'):
        self.filename = filename
        self.access = access
        self.f = h5py.File(self.filename, self.access)

    def __enter__(self):
        self.f = h5py.File(self.filename, self.access)
        return self

    def __exit__(self, *args):
        self.close()

    def save_attributes(self, attributes):
        for key, value in attributes.items():
            self.f.attrs[key] = value

    def save_adc(self, name, bins, counts, energies):
        adc = self.f.create_group(name)
        adc.attrs['bins'] = bins
        adc.create_dataset('counts', data=counts, shape=(bins,))
        adc.create_dataset('energies', data=energies, shape=(bins,))

    def read_attributes(self):
        return {key: value for key, value in self.f.attrs.items()}

    def read_adc(self, name):
        adc_group = self.f[name]
        bins = adc_group.attrs['bins']
        counts = numpy.array(adc_group['counts'])
        energies = numpy.array(adc_group['energies'])
        return bins, counts, energies

    def close(self):
        self.f.close()

{'fraction_non_alphanumeric': 0.12777526053466243, 'fraction_numerical': 0.0022655188038060714, 'mean_word_length': 2.704697986577181, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1143035', 'n_tokens_mistral': 725, 'n_tokens_neox': 701, 'n_words': 161}