def _validate(self, args, i): arg = super(Interval, self)._validate(args, i) unit = arg.type().unit if self.allowed_units is not None and unit not in self.allowed_units: msg = 'Interval unit `{}` is not among the allowed ones {}' raise IbisTypeError(msg.format(unit, self.allowed_units)) return arg
def _validate(self, args, i): arg = args[i] if not self.case_sensitive: arg = self._preferred_case(arg) if arg not in self.options: raise IbisTypeError('{} not among options {}'.format( arg, self.options)) return arg
def _validate(self, args, i): arg = args[i] if not isinstance(arg, ir.TableExpr): raise IbisTypeError('Argument must be a table.') if self.schema is not None: self.schema.validate(arg) return arg
def validate(self, arg): if isinstance(arg, ir.TableExpr): # Check that columns match the schema first for column_rule in self.rules: if column_rule.name not in arg: if column_rule.optional: continue else: raise IbisTypeError('No column with name {}.'.format( column_rule.name)) column = arg[column_rule.name] try: # Arguments must validate the column column_rule.validate([column], 0) except IbisTypeError as e: six.raise_from( IbisTypeError('Could not satisfy rule: {}.'.format( str(column_rule))), e)
def _validate(self, args, i): arg = args[i] if not self._type_matches(arg): if isinstance(self.fail_message, py_string): exc = self.fail_message else: exc = self.fail_message(self.types, arg) raise IbisTypeError(exc) return arg
def _validate(self, args, types): clean_args = list(args) for i, validator in enumerate(types): try: clean_args[i] = validator.validate(clean_args, i) except IbisTypeError as e: exc = e.args[0] msg = ('Argument {0}: {1}'.format(i, exc) + '\nArgument was: {0}'.format(ir._safe_repr(args[i]))) raise IbisTypeError(msg) return clean_args
def _validate(self, args, i): validated = False for t in self.types: try: arg = t.validate(args, i) validated = True except: pass else: break if not validated: raise IbisTypeError('No type options validated') return arg
def _validate(self, args, i): arg = args[i] if not isinstance(arg, list): arg = args[i] = list(arg) assert isinstance(arg, list), 'not a list in ListOf validation' if len(arg) < self.min_length: raise IbisTypeError('list must have at least {} elements'.format( self.min_length)) checked_args = [] for j in range(len(arg)): try: checked_arg = self.value_type.validate(arg, j) except IbisTypeError as e: exc = e.args[0] msg = ('List element {0} had a type error: {1}'.format(j, exc)) raise IbisTypeError(msg) checked_args.append(checked_arg) args[i] = checked_args return ir.as_value_expr(checked_args)
def _validate(self, args, i): arg = args[i] if arg not in self.options: raise IbisTypeError('{0} not among options {1}'.format( arg, repr(self.options))) return arg
def _validate_impala_type(t): if t in _impala_to_ibis.keys(): return t elif ir._DECIMAL_RE.match(t): return t raise IbisTypeError("Not a valid Impala type for UDFs")