def _basic_comparison(self, operation, other):
     if isinstance(other, Range):
         utils.validate_timestamp_matching(self.data.f0, other.data.f0)
         new_data = utils.create_bool_rec_array(len(self.data.f0))
         try:
             new_data.f0 = self.data.f0
             if operation == 'gte':
                 new_data.f1 = self.data.f1 >= other.data.f1
             elif operation == 'gt':
                 new_data.f1 = self.data.f1 > other.data.f1
             elif operation == 'lte':
                 new_data.f1 = self.data.f1 <= other.data.f1
             elif operation == 'lt':
                 new_data.f1 = self.data.f1 < other.data.f1
         except ValueError:
             raise Exception('Cannot compare uneven ranges')
         return BooleanRange(self.definition, new_data)
     elif isinstance(other, (int, float)):
         new_data = utils.create_bool_rec_array(len(self.data.f0))
         new_data.f0 = self.data.f0
         if operation == 'gte':
             new_data.f1 = self.data.f1 >= other
         elif operation == 'gt':
             new_data.f1 = self.data.f1 > other
         elif operation == 'lte':
             new_data.f1 = self.data.f1 <= other
         elif operation == 'lt':
             new_data.f1 = self.data.f1 < other
         return BooleanRange(self.definition, new_data)
     else:
         raise Exception('Not Implemented')
    def _basic_math(self, operation, other):
        if isinstance(other, Range):
            utils.validate_timestamp_matching(self.data.f0, other.data.f0)
            new_data = utils.create_rec_array(len(self.data.f0))
            try:
                new_data.f0 = (self.data.f0 + other.data.f0) / 2
                if operation == 'add':
                    new_data.f1 = self.data.f1 + other.data.f1
                elif operation == 'sub':
                    new_data.f1 = self.data.f1 - other.data.f1
                elif operation == 'mul':
                    new_data.f1 = self.data.f1 * other.data.f1
                elif operation == 'div':
                    new_data.f1 = self.data.f1 / other.data.f1
            except ValueError:
                raise Exception('Cannot add uneven ranges')
            new_definition = utils.reduce_definitions(self.definition,
                                                      other.definition)
            return Range(new_definition, new_data)

        elif isinstance(other, (int, float)):
            new_data = utils.create_rec_array(len(self.data.f0))
            new_data.f0 = self.data.f0
            if operation == 'add':
                new_data.f1 = self.data.f1 + other
            elif operation == 'sub':
                new_data.f1 = self.data.f1 - other
            elif operation == 'mul':
                new_data.f1 = self.data.f1 * other
            elif operation == 'div':
                new_data.f1 = self.data.f1 / other
            return Range(self.definition, new_data)

        else:
            raise Exception('Not Implemented')
 def __or__(self, other):
     if isinstance(other, BooleanRange):
         utils.validate_timestamp_matching(self.data.f0, other.data.f0)
         new_data = utils.create_bool_rec_array(len(self.data.f0))
         try:
             new_data.f0 = self.data.f0
             new_data.f1 = numpy.logical_or(self.data.f1, other.data.f1)
         except ValueError:
             raise Exception('Cannot combine uneven ranges')
         return BooleanRange(self.definition, new_data)
     else:
         raise Exception('Not Implemented')
 def __or__(self, other):
     if isinstance(other, BooleanBinnedRange):
         if len(self.data) != len(other.data):
             raise Exception('Cannot compare uneven BinnedRanges')
         utils.validate_timestamp_matching(self.bins, other.bins)
         new_data = []
         for i in range(len(self.data)):
             result_data = utils.create_bool_rec_array(len(self.data[i].f0))
             try:
                 result_data.f0 = self.data[i].f0
                 result_data.f1 = numpy.logical_or(self.data[i].f1,
                                                   other.data[i].f1)
                 new_data.append(result_data)
             except ValueError:
                 raise Exception('Cannot compare mismatched bins')
         return BooleanBinnedRange(self.definition, self.bins, new_data)
     else:
         raise Exception('Not Implemented')
    def _basic_math(self, operation, other):
        if isinstance(other, BinnedRange):
            if len(self.data) != len(other.data):
                raise Exception('Cannot add uneven BinnedRanges')
            utils.validate_timestamp_matching(self.bins, other.bins)
            new_data = []
            for i in range(len(self.data)):
                result_data = utils.create_rec_array(len(self.data[i].f0))
                try:
                    result_data.f0 = (self.data[i].f0 + other.data[i].f0) / 2
                    if operation == 'add':
                        result_data.f1 = self.data[i].f1 + other.data[i].f1
                    elif operation == 'sub':
                        result_data.f1 = self.data[i].f1 - other.data[i].f1
                    elif operation == 'mul':
                        result_data.f1 = self.data[i].f1 * other.data[i].f1
                    elif operation == 'div':
                        result_data.f1 = self.data[i].f1 / other.data[i].f1
                    new_data.append(result_data)
                except ValueError:
                    raise Exception('Cannot add mismatched bins')
            new_definition = utils.reduce_definitions(self.definition,
                                                      other.definition)
            new_bins = (self.bins + other.bins) / 2

            return BinnedRange(new_definition, new_bins, new_data)
        elif isinstance(other, (int, float)):
            new_data = []
            for data in self.data:
                result_data = utils.create_rec_array(len(self.data.f0))
                result_data.f0 = data.f0
                if operation == 'add':
                    result_data.f1 = data.f1 + other
                elif operation == 'sub':
                    result_data.f1 = data.f1 - other
                elif operation == 'mul':
                    result_data.f1 = data.f1 * other
                elif operation == 'div':
                    result_data.f1 = data.f1 / other
                new_data.append(result_data)
            return BinnedRange(self.definition, self.bins, new_data)
        else:
            raise Exception('Not Implemented')
 def _basic_comparison(self, operation, other):
     if isinstance(other, BinnedRange):
         if len(self.data) != len(other.data):
             raise Exception('Cannot compare uneven BinnedRanges')
         utils.validate_timestamp_matching(self.bins, other.bins)
         new_data = []
         for i in range(len(self.data)):
             result_data = utils.create_bool_rec_array(len(self.data[i].f0))
             try:
                 result_data.f0 = self.data[i].f0
                 if operation == 'gte':
                     result_data.f1 = self.data[i].f1 >= other.data[i].f1
                 elif operation == 'gt':
                     result_data.f1 = self.data[i].f1 > other.data[i].f1
                 elif operation == 'lte':
                     result_data.f1 = self.data[i].f1 <= other.data[i].f1
                 elif operation == 'lt':
                     result_data.f1 = self.data[i].f1 < other.data[i].f1
                 new_data.append(result_data)
             except ValueError:
                 raise Exception('Cannot compare mismatched bins')
         return BooleanBinnedRange(self.definition, self.bins, new_data)
     elif isinstance(other, (int, float)):
         new_data = []
         for data in self.data:
             result_data = utils.create_bool_rec_array(len(data.f0))
             result_data.f0 = data.f0
             if operation == 'gte':
                 result_data.f1 = data.f1 >= other
             elif operation == 'gt':
                 result_data.f1 = data.f1 > other
             elif operation == 'lte':
                 result_data.f1 = data.f1 <= other
             elif operation == 'lt':
                 result_data.f1 = data.f1 < other
             new_data.append(result_data)
         return BooleanBinnedRange(self.definition, self.bins, new_data)
     else:
         raise Exception('Not Implemented')