<commit_before>import h5py
import os
import re


class H5Explorer(object):
    def __init__(self, filename, mode="r"):
        self.__file = h5py.File(filename, mode)
        self.__working_dir = "/"

        self.__dir_queue = list()

    def __get_absolute_path(self, path):
        if path is None:
            path = self.__working_dir
        elif not path.startswith("/"):
            path = "/".join(self.__working_dir.split("/") + path.split("/"))

        return re.sub("/+", "/", os.path.normpath(path))

    @property
    def working_dir(self):
        return self.__working_dir

    def change_dir(self, new_dir="/"):
        new_dir = self.__get_absolute_path(new_dir)

        if new_dir in self.__file:
            if isinstance(self.__file[new_dir], h5py.Dataset):
                raise ValueError("{} exists, but is not a directory".format(new_dir))
            self.__working_dir = new_dir
        else:
            raise ValueError("Directory {} does not exist.".format(new_dir))

    def push_dir(self, new_dir):
        new_dir = self.__get_absolute_path(new_dir)

        self.__dir_queue.append(self.__working_dir)
        self.change_dir(new_dir)

    def pop_dir(self):
        if len(self.__dir_queue) == 0:
            raise IndexError("Cannot pop a directory before pushing one.")
        self.__working_dir = self.__dir_queue.pop()

    def list_groups(self, target_dir=None):
        target_dir = self.__get_absolute_path(target_dir)

        if target_dir not in self.__file:
            raise ValueError("Directory {} does not exist.".format(target_dir))

        return [ k for k, v in self.__file[target_dir].items()
                 if isinstance(v, h5py.Group) ]

    def list_datasets(self, target_dir=None):
        target_dir = self.__get_absolute_path(target_dir)

        if target_dir not in self.__file:
            raise ValueError("Directory {} does not exist.".format(target_dir))

        return [ k for k, v in self.__file[target_dir].items()
                 if isinstance(v, h5py.Dataset) ]

    def create_group(self, group_dir):
        group_dir = self.__get_absolute_path(group_dir)
        self.__file.create_group(group_dir)<commit_msg>(Closes #14) Added delete_group()<commit_after>import h5py
import os
import re


class H5Explorer(object):
    def __init__(self, filename, mode="r"):
        self.__file = h5py.File(filename, mode)
        self.__working_dir = "/"

        self.__dir_queue = list()

    def __get_absolute_path(self, path):
        if path is None:
            path = self.__working_dir
        elif not path.startswith("/"):
            path = "/".join(self.__working_dir.split("/") + path.split("/"))

        return re.sub("/+", "/", os.path.normpath(path))

    def __check_group(self, path):
        path = self.__get_absolute_path(path)
        if path not in self.__file:
            raise ValueError("Directory {} does not exist.".format(path))
        elif not isinstance(self.__file[path], h5py.Group):
            raise ValueError("{} exists, but is not a directory".format(path))
        else:
            return path

    @property
    def working_dir(self):
        return self.__working_dir

    def change_dir(self, new_dir="/"):
        new_dir = self.__check_group(new_dir)
        self.__working_dir = new_dir

    def push_dir(self, new_dir):
        new_dir = self.__get_absolute_path(new_dir)

        self.__dir_queue.append(self.__working_dir)
        self.change_dir(new_dir)

    def pop_dir(self):
        if len(self.__dir_queue) == 0:
            raise IndexError("Cannot pop a directory before pushing one.")
        self.__working_dir = self.__dir_queue.pop()

    def list_groups(self, target_dir=None):
        target_dir = self.__check_group(target_dir)

        return [k for k, v in self.__file[target_dir].items()
                if isinstance(v, h5py.Group)]

    def list_datasets(self, target_dir=None):
        target_dir = self.__check_group(target_dir)

        return [k for k, v in self.__file[target_dir].items()
                if isinstance(v, h5py.Dataset)]

    def create_group(self, group_dir):
        group_dir = self.__get_absolute_path(group_dir)
        self.__file.create_group(group_dir)

    def delete_group(self, group_dir):
        group_dir = self.__check_group(group_dir)
        del self.__file[group_dir]
{'fraction_non_alphanumeric': 0.11315547378104876, 'fraction_numerical': 0.0036798528058877645, 'mean_word_length': 2.5942148760330577, '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': '3990959', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1319, 'n_words': 292}