<commit_before># <NAME> <<EMAIL>>

##____________________________________________________________________________||
class GenericKeyComposerB(object):
    def __init__(self, varNames, binnings, indices = None):
        self.varNames = varNames
        self.binnings = binnings
        self.indices = indices if indices is not None else [None]*len(self.varNames)

    def begin(self, event):
        self._zip = self._zipArrays(event)

    def __call__(self, event):
        if self._zip is None: return ()
        ret = [ ]
        for branche, binning, index in self._zip:
            if index is not None:
                if len(branche) <= index: return ()
                var = branche[index]
            else:
                var = branche[0]
            var_bin = binning(var)
            if var_bin is None: return ()
            ret.append(var_bin)
        return (tuple(ret), )

    def _zipArrays(self, event):
        self.branches = [ ]
        for varname in self.varNames:
            try:
                branch = getattr(event, varname)
            except AttributeError, e:
                import logging
                logging.warning(e)
                return None
            self.branches.append(branch)
        return zip(self.branches, self.binnings, self.indices)

##____________________________________________________________________________||
class GenericKeyComposerBFactory(object):
    def __init__(self, varNames, binnings, indices = None):
        self.varNames = varNames
        self.binnings = binnings
        self.indices = indices
    def __call__(self):
        return GenericKeyComposerB(varNames = self.varNames, binnings = self.binnings, indices = self.indices)

##____________________________________________________________________________||
<commit_msg>add a docstring in GenericKeyComposerB<commit_after># <NAME> <<EMAIL>>

##____________________________________________________________________________||
class GenericKeyComposerB(object):
    """This class is a faster of GenericKeyComposer.

    This class can be used with BEvents.

    (this docstring is under development.)

    """
    def __init__(self, varNames, binnings, indices = None):
        self.varNames = varNames
        self.binnings = binnings
        self.indices = indices if indices is not None else [None]*len(self.varNames)

    def begin(self, event):
        self._zip = self._zipArrays(event)

    def __call__(self, event):
        if self._zip is None: return ()
        ret = [ ]
        for branche, binning, index in self._zip:
            if index is not None:
                if len(branche) <= index: return ()
                var = branche[index]
            else:
                var = branche[0]
            var_bin = binning(var)
            if var_bin is None: return ()
            ret.append(var_bin)
        return (tuple(ret), )

    def _zipArrays(self, event):
        self.branches = [ ]
        for varname in self.varNames:
            try:
                branch = getattr(event, varname)
            except AttributeError, e:
                import logging
                logging.warning(e)
                return None
            self.branches.append(branch)
        return zip(self.branches, self.binnings, self.indices)

##____________________________________________________________________________||
class GenericKeyComposerBFactory(object):
    def __init__(self, varNames, binnings, indices = None):
        self.varNames = varNames
        self.binnings = binnings
        self.indices = indices
    def __call__(self):
        return GenericKeyComposerB(varNames = self.varNames, binnings = self.binnings, indices = self.indices)

##____________________________________________________________________________||

{'fraction_non_alphanumeric': 0.08618403606470432, 'fraction_numerical': 0.0005303632988597189, 'mean_word_length': 2.4259763851044505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '3212291', 'n_tokens_mistral': 957, 'n_tokens_neox': 937, 'n_words': 255}