<commit_before># system imports
import numpy as np
import pdb

# local imports
import Maybe


class FoldResult(object):
    '''Computations on a cross validation fold.'''

    def __init__(self):
        self.actuals = np.array([])
        self.estimates = np.array([])

    def extend(self, actuals, estimates):
        '''Extend the collection of values.

        Args
        actuals   1D np.array
        estimates 1D np.array

        Returns: None
        '''
        if len(actuals) != len(estimates):
            print 'len(actuals)', len(actuals)
            print 'len(estimates)', len(estimates)
            raise ValueError('lengths differ')
        self.actuals = np.append(self.actuals, actuals)
        self.estimates = np.append(self.estimates, estimates)

    def maybe_errors(self):
        '''Return Maybe(vector of errors, without nans).'''
        errors = self.actuals - self.estimates
        if np.isnan(errors).all():
            # return NoValue, if
            # - errors.size == 0 OR
            # - every element of errors is nan
            # NOTE: The one test does it all
            return Maybe.NoValue()
        else:
            errors_without_nans = errors[~np.isnan(errors)]
            return Maybe.Maybe(errors_without_nans)
#
#
#
#
#    def root_mean_squared_error(self):
#        '''Return number or NaN.'''
#
#        pass
#
#    def mean_absolute_error(self):
#        '''Return number of NaN.'''
#        pass
#
#    def reduce_errors_ignore_nans(self, reduction):
#        '''Reduce the non-nan errors.'''
#        errors = self.actuals - self.estimates
#        if np.isnan(errors).all():
#            # return NoValue, if
#            # - errors.size == 0 OR
#            # - every element of errors is nan
#            # NOTE: The one test does it all
#            return Maybe.NoValue()
#        else:
#            return Maybe.Maybe(reduction(errors))
#
#    def mean_error_ignore_nans(self):
#        '''Return Maybe(number), ignoring actuals or estimates with Nan or Inf.
#        '''
#        return self.reduce_errors_ignore_nans(np.nanmean)
#
#    def median_error_ignore_nans(self):
#        '''Return median error or NaN, ignoring actuals or estimates with NaN.
#        '''
#        return self.reduce_errors_ignore_nans(np.nanmedian)
#
#    def root_mean_squared_error_ignore_nans(self):
#        errors = self._maybe_errors()
#        if errors.has_value:
#            # write me
#        else:
#            return errors
#
#    def mean_absolute_error_ignore_nans(self):
#        pass
#

if __name__ == '__main__':<commit_msg>remove dead code<commit_after># system imports
import numpy as np
import pdb

# local imports
import Maybe


class FoldResult(object):
    '''Computations on a cross validation fold.'''

    def __init__(self):
        self.actuals = np.array([])
        self.estimates = np.array([])

    def extend(self, actuals, estimates):
        '''Extend the collection of values.

        Args
        actuals      1D np.array
        estimates    1D np.array

        Returns: None
        '''
        if len(actuals) != len(estimates):
            print 'len(actuals)', len(actuals)
            print 'len(estimates)', len(estimates)
            raise ValueError('lengths differ')
        self.actuals = np.append(self.actuals, actuals)
        self.estimates = np.append(self.estimates, estimates)

    def maybe_errors(self):
        '''Return Maybe(vector of errors, without nans).'''
        errors = self.actuals - self.estimates
        if np.isnan(errors).all():
            # return NoValue, if
            # - errors.size == 0 OR
            # - every element of errors is nan
            # NOTE: The one test does it all
            return Maybe.NoValue()
        else:
            errors_without_nans = errors[~np.isnan(errors)]
            return Maybe.Maybe(errors_without_nans)

if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.11125352473724685, 'fraction_numerical': 0.0017944116893104333, 'mean_word_length': 2.1291098636728147, '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': '3893720', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1131, 'n_words': 304}