Check validity of parameters and raise ValueError if not valid.
960023
def _check_params(self):
        
        self.n_estimators = int(self.n_estimators)
        if self.n_estimators <= 0:
            raise ValueError("n_estimators must be greater than 0 but "
                             "was %r" % self.n_estimators)

        if not 0.0 < self.learning_rate <= 1.0:
            raise ValueError("learning_rate must be within ]0; 1] but "
                             "was %r" % self.learning_rate)

        if not 0.0 < self.subsample <= 1.0:
            raise ValueError("subsample must be in ]0; 1] but "
                             "was %r" % self.subsample)

        if not 0.0 <= self.dropout_rate < 1.0:
            raise ValueError("dropout_rate must be within [0; 1[, but "
                             "was %r" % self.dropout_rate)

        max_features = self._check_max_features()

        self.min_samples_split = int(self.min_samples_split)
        self.min_samples_leaf = int(self.min_samples_leaf)
        self.max_depth = int(self.max_depth)
        if self.max_leaf_nodes:
            self.max_leaf_nodes = int(self.max_leaf_nodes)

        self.max_features_ = max_features

        allowed_presort = ('auto', True, False)
        if self.presort not in allowed_presort:
            raise ValueError("'presort' should be in {}. Got {!r} instead."
                             .format(allowed_presort, self.presort))

        if self.loss not in LOSS_FUNCTIONS:
            raise ValueError("Loss '{0:s}' not supported. ".format(self.loss))
913527
def _validate(self,val):
        """"""
        if isinstance(self.class_, tuple):
            class_name = ('(%s)' % ', '.join(cl.__name__ for cl in self.class_))
        else:
            class_name = self.class_.__name__
        if self.is_instance:
            if not (isinstance(val,self.class_)) and not (val is None and self.allow_None):
                raise ValueError(
                    "Parameter '%s' value must be an instance of %s, not '%s'" %
                    (self.name, class_name, val))
        else:
            if not (val is None and self.allow_None) and not (issubclass(val,self.class_)):
                raise ValueError(
                    "Parameter '%s' must be a subclass of %s, not '%s'" %
                    (val.__name__, class_name, val.__class__.__name__))
322520
def is_valid(self, value):
        ''' 

        '''
        try:
            if validation_on():
                self.validate(value, False)
        except ValueError:
            return False
        else:
            return True
292559
def validate_is_callable_or_none(option, value):
    """"""
    if value is None:
        return value
    if not callable(value):
        raise ValueError("%s must be a callable" % (option,))
    return value
811144
def value_check(arg_name, pos, allowed_values):
    

    def decorator(fn):

        # brevity compromised in favour of readability
        def logic(*args, **kwargs):
            arg_count = len(args)
            if arg_count:
                if pos < arg_count:
                    if args[pos] in allowed_values:
                        return fn(*args, **kwargs)
                    else:
                        raise ValueError(
                            "'{0}' at position {1} not in allowed values {2}".format(args[pos], pos, allowed_values))
                else:
                    if arg_name in kwargs:
                        value = kwargs[arg_name]
                        if value in allowed_values:
                            return fn(*args, **kwargs)
                        else:
                            raise ValueError("'{0}' is not an allowed kwarg".format(arg_name))
                    else:
                        # partially applied functions because of incomplete args, let python handle this
                        return fn(*args, **kwargs)
            else:
                if arg_name in kwargs:
                    value = kwargs[arg_name]
                    if value in allowed_values:
                        return fn(*args, **kwargs)
                else:
                    raise ValueError("'{0}' is not an allowed kwarg".format(arg_name))

        return logic

    return decorator
717686
def check(self):
        
        try:
            value = self.raw_value
        except (AttributeError, KeyError) as err:
            self._reraise_if_required(err)
        else:
            if self.checker:
                self.checker(self.full_name, value)
            try:
                self.validate(value)
                self.run_validators(value)
            except ValidationError as error:
                raise ValueError("Setting {} has an invalid value: {}".format(self.full_name, error))
617534
def _validate_params(self):
        
        if self.expectile >= 1 or self.expectile <= 0:
            raise ValueError('expectile must be in (0,1), but found {}'.format(self.expectile))
        self.distribution = NormalDist(scale=self.scale)
        super(ExpectileGAM, self)._validate_params()
387160
def _validate(cls, kind):
        """"""
        if kind not in cls._valid_kinds:
            mesg = "'kind' must be one of {}, {}, {}, or {}."
            raise ValueError(mesg.format(*cls._valid_kinds))
        else:
            return kind
702957
def valid_level(value):
    """"""
    value = value.upper()
    if getattr(logging, value, None) is None:
        raise argparse.ArgumentTypeError("%s is not a valid level" % value)
    return value
177584
def validate(self, value):
        
        if value in self.empty_values and self.required:
            raise ValidationError(self.error_messages['required'])
1331891
def Validate(self, value):
    """"""
    if isinstance(value, string_types):
      raise TypeValueError("Value must be an iterable not a string.")

    elif not isinstance(value, (list, tuple)):
      raise TypeValueError("%r not a valid List" % value)

    # Validate each value in the list validates against our type.
    return [self.validator.Validate(val) for val in value]
886005
def _parse_arguments(self, method, parameters):
    """"""

    # TODO: Consider raising an exception if there are extra arguments.

    arguments = _fetch_arguments(self, method)

    arg_dict = {}
    errors = []
    for key, properties in parameters:
        if key in arguments:
            value = arguments[key]
            try:
                arg_dict[key] = _apply_validator_chain(
                    properties.get('validators', []), value, self)
            except validators.ValidationError as err:
                errors.append(err)
        else:
            if properties.get('required', False):
                raise web.HTTPError(
                    400,
                    ('Missing required parameter: %s'
                     % (key, ))
                    )
            else:
                if properties.get('default', None) is not None:
                    arg_dict[key] = properties['default']
                else:
                    arg_dict[key] = None
    if errors:
        raise web.HTTPError(400, 'There were %s errors' % len(errors))

    return arg_dict
1065987
def validate_values(func, dic):
    
    for value_name, value in dic.items():
        if not func(value):
            raise ValueError('{} can not be {}'.format(value_name, value))
781587
def validate(self,value):
        """"""
        if self.validator is not None:
            try:
                valid = self.validator(value)
            except Exception as e:
                import pdb; pdb.set_trace()
            if isinstance(valid, tuple) and len(valid) == 2:
                valid, errormsg = valid
            elif isinstance(valid, bool):
                errormsg = "Invalid value"
            else:
                raise TypeError("Custom validator must return a boolean or a (bool, errormsg) tuple.")
            if valid:
                self.error = None
            else:
                self.error = errormsg
            return valid
        else:
            self.error = None #reset error
            return True
1342514
def validate(self):
        
        errors = []
        for param in self.required_params:
            if (not hasattr(self, param) or getattr(self, param) is None):
                errors.append("missing %s parameter" % (param))
        if (len(errors) > 0):
            raise IIIFInfoError("Bad data for info.json: " + ", ".join(errors))
        return True
462295
def _validate(self, val):
        
        if not self.check_on_set:
            self._ensure_value_is_in_objects(val)
            return

        if not (val in self.objects or (self.allow_None and val is None)):
            # CEBALERT: can be called before __init__ has called
            # super's __init__, i.e. before attrib_name has been set.
            try:
                attrib_name = self.name
            except AttributeError:
                attrib_name = ""

            items = []
            limiter = ']'
            length = 0
            for item in self.objects:
                string = str(item)
                length += len(string)
                if length < 200:
                    items.append(string)
                else:
                    limiter = ', ...]'
                    break
            items = '[' + ', '.join(items) + limiter
            raise ValueError("%s not in Parameter %s's list of possible objects, "
                             "valid options include %s"%(val,attrib_name, items))
617452
def validate(self):
        """"""
        if self.error:
            return False

        for v in self.validators:
            self.error = v(self.value)
            if self.error:
                return False

        return True