Cleans and returns the given value, or raises a ParameterNotValidError exception

def clean(self, value):
        """Cleans and returns the given value, or raises a ParameterNotValidError exception"""

        if isinstance(value, numbers.Number):
            return value
        elif isinstance(value, six.string_types):
            try:
                value = float(value)
                return int(value) if value.is_integer() else value
            except ValueError:
                raise ParameterNotValidError

        raise ParameterNotValidError