<commit_before>import sys
import random
import math
import collections

import sortedcontainers


class Histogram(sortedcontainers.SortedDict):

    def __init__(self, data=()):
        super(Histogram, self).__init__()
        for datum in data:
            self[datum] += 1

    def __getitem__(self, key):
        try:
            result = super(Histogram, self).__getitem__(key)
        except KeyError:
            result = 0
        return result

    def total(self):
        """Sum of values."""
        return sum(self.itervalues())

    def mean(self):
        """Mean of the distribution."""
        weighted_sum = sum(count * value for value, count in self.iteritems())
        return weighted_sum / float(self.total())<commit_msg>Making TypeError more informative for unhashable distribution<commit_after>import sys
import random
import math
import collections

import sortedcontainers


class Histogram(sortedcontainers.SortedDict):

    def __init__(self, data=()):
        super(Histogram, self).__init__()
        for datum in data:
            self[datum] += 1

    def __getitem__(self, key):
        try:
            result = super(Histogram, self).__getitem__(key)
        except KeyError:
            result = 0
        except TypeError:
            msg = "Can't make histogram of unhashable type (%s)" % type(key)
            raise TypeError(msg)
        return result

    def total(self):
        """Sum of values."""
        return sum(self.itervalues())

    def mean(self):
        """Mean of the distribution."""
        weighted_sum = sum(count * value for value, count in self.iteritems())
        return weighted_sum / float(self.total())
{'fraction_non_alphanumeric': 0.10119760479041916, 'fraction_numerical': 0.0023952095808383233, 'mean_word_length': 2.48125, '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': '71564', 'n_tokens_mistral': 478, 'n_tokens_neox': 453, 'n_words': 138}