<commit_before>import pandas as pd


class Groups(object):
    """
    Groups are described by a bipartite graph. With Group vs. Members. A member can be in multiple groups.
    A member can not be a group and a group can not be member of a different group.
    """
    @staticmethod
    def __verify_name(names):
        x = names[0]
        for name in names:
            assert name == x
        return x

    def __init__(self, data):
        self.__data = data
        self.__groups = [group_id for group_id in data.index.get_level_values(level="Group ID").unique()]
        self.__owns = pd.Series({group_id: list(self.__data.xs(group_id, level="Group ID").index) for group_id in self.__groups})
        self.__name = pd.Series({group_id: Groups.__verify_name(self.__data.xs(group_id, level="Group ID")["Group Name"])
                                 for group_id in self.__groups})

        assert len(self.__name.unique()) == len(self.__name)

    @property
    def groups(self):
        return self.__groups

    @property
    def name(self):
        """
        Series {group_id_i: name_i}
        :return:
        """
        return self.__name

    @property
    def group_id(self):
        """
        Series {name_i: group_id_i}
        :return:
        """
        return pd.Series({v: k for k, v in self.name.items()})

    @property
    def group_holdings(self):
        """
        Series {group_id_i : [member_1, ...]}
        :return:
        """
        #todo: I wish there would be a simple method to link from member_1 to account_1_of_member_1, account_2_of...
        #todo: This would make connecting with the transaction table a lot simpler
        return self.__owns<commit_msg>make groups a dictionary of groups<commit_after>class Group(object):
    def __repr__(self, *args, **kwargs):
        return "Group {0} owns {1}".format(self.name, self.owns)

    def __init__(self, name, owns):
        self.name = name
        self.owns = owns


class Groups(dict):
    """
    Groups are described by a bipartite graph. With Group vs. Members. A member can be in multiple groups.
    A member can not be a group and a group can not be member of a different group.
    """
    @staticmethod
    def __verify_name(names):
        x = names[0]
        for name in names:
            assert name == x
        return x

    def __init__(self, data, **kwargs):
        super().__init__(**kwargs)
        groups = [group_id for group_id in data.index.get_level_values(level="Group ID").unique()]
        name = {group_id: Groups.__verify_name(data.xs(group_id, level="Group ID")["Group Name"]) for group_id in groups}
        owns = {group_id: list(data.xs(group_id, level="Group ID").index) for group_id in groups}
        self.__name = {group_id: Group(name=name[group_id], owns=owns[group_id]) for group_id in groups}

    def __getitem__(self, item):
        return self.__name[item]

    def items(self):
        return self.__name.items()

    def values(self):
        return self.__name.values()

    def keys(self):
        return self.__name.keys()

    def __iter__(self):
        return self.__name.__iter__()
{'fraction_non_alphanumeric': 0.11026131293817719, 'fraction_numerical': 0.0028680688336520078, 'mean_word_length': 2.4494505494505496, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5906365', 'n_tokens_mistral': 950, 'n_tokens_neox': 926, 'n_words': 292}