<commit_before>from abc import (
    ABCMeta,
    abstractproperty
)

from zipline.protocol import DATASOURCE_TYPE
from zipline.utils.protocol_utils import ndict


class DataSource(object):

    __metaclass__ = ABCMeta

    @property
    def event_type(self):
        return DATASOURCE_TYPE.TRADE

    @property
    def mapping(self):
        """
        Mappings of the form:
        target_key: (mapping_function, source_key)
        """
        return {}

    @abstractproperty
    def raw_data(self):
        """
        An iterator that yields the raw datasource,
        in chronological order of data, one event at a time.
        """
        NotImplemented

    @abstractproperty
    def instance_hash(self):
        """
        A hash that represents the unique args to the source.
        """
        pass

    def get_hash(self):
        return self.__class__.__name__ + "-" + self.instance_hash

    def apply_mapping(self, raw_row):
        """
        Override this to hand craft conversion of row.
        """
        row = {target: mapping_func(raw_row[source_key])
               for target, (mapping_func, source_key)
               in self.mapping.items()}
        row.update({'source_id': self.get_hash()})
        row.update({'type': self.event_type})
        return row

    @property
    def mapped_data(self):
        for row in self.raw_data:
            yield ndict(self.apply_mapping(row))

    def __iter__(self):
        return self

    def next(self):
        return self.mapped_data.next()
<commit_msg>Changes type emitted from DataSource to Event.<commit_after>from abc import (
    ABCMeta,
    abstractproperty
)

from zipline.protocol import DATASOURCE_TYPE
from zipline.protocol import Event


class DataSource(object):

    __metaclass__ = ABCMeta

    @property
    def event_type(self):
        return DATASOURCE_TYPE.TRADE

    @property
    def mapping(self):
        """
        Mappings of the form:
        target_key: (mapping_function, source_key)
        """
        return {}

    @abstractproperty
    def raw_data(self):
        """
        An iterator that yields the raw datasource,
        in chronological order of data, one event at a time.
        """
        NotImplemented

    @abstractproperty
    def instance_hash(self):
        """
        A hash that represents the unique args to the source.
        """
        pass

    def get_hash(self):
        return self.__class__.__name__ + "-" + self.instance_hash

    def apply_mapping(self, raw_row):
        """
        Override this to hand craft conversion of row.
        """
        row = {target: mapping_func(raw_row[source_key])
               for target, (mapping_func, source_key)
               in self.mapping.items()}
        row.update({'source_id': self.get_hash()})
        row.update({'type': self.event_type})
        return row

    @property
    def mapped_data(self):
        for row in self.raw_data:
            yield Event(self.apply_mapping(row))

    def __iter__(self):
        return self

    def next(self):
        return self.mapped_data.next()

{'fraction_non_alphanumeric': 0.08934930398187116, 'fraction_numerical': 0.0, 'mean_word_length': 2.169230769230769, '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': '5262469', 'n_tokens_mistral': 903, 'n_tokens_neox': 865, 'n_words': 238}