Try to auto-detect the numeric type of the value. First a conversion to
    int is tried. If this fails float is tried, and if that fails too, unicode()
    is executed. If this also fails, a ValueError is raised.
344577
def parse_number(val, use_dateutilparser=False):
    
    if use_dateutilparser:
        funcs = [int, float, parse_list_from_string,
                 dateutil.parser.parse, str]
    else:
        funcs = [int, float, parse_list_from_string, str]
    if (val.strip().startswith("'") and val.strip().endswith("'")) or (val.strip().startswith('"') and val.strip().endswith('"')):
        return val[1:-1]
    for f in funcs:
        try:
            return f(val)
        # eat exception
        except (ValueError, UnicodeEncodeError, UnicodeDecodeError) as ve:
            pass
    raise ValueError('Cannot parse number:', val)
10202
def check_value_and_type(value, data_type):
        
        if value is not None and data_type is not type(None):
            # if not isinstance(value, data_type):
            if not type_inherits_of_type(data_type, type(value)):
                raise TypeError(
                    "Value: '{0}' is not of data type: '{1}', value type: {2}".format(value, data_type, type(value)))
1082308
def value(self):
        
        if self.opts['int']:
            return int(self.val)
        else:
            return float(self.val)
529888
def _is_numeric_data(ll):
    
    for l in ll:
        try:
            if any(math.isnan(float(i)) or isinstance(i, str) for i in l):
                return False
            # if not all(isinstance(i, (int, float)) or math.isnan(float(i)) for i in l):
            #     # There is an entry that is a non-numeric entry in this list
            #     return False
        except ValueError:
            # Trying to case a str as a float didnt work, and we got an error
            return False
    # All arrays are 100% numeric or "nan" entries.
    return True
1018769
def isNumber(s):
    
    s = s.replace(',', '')
    try:
        float(s)
        return True
    except ValueError:
        pass
    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError) as e:
        pass
    return False
70379
def is_numeric(self):
        
        from decimal import Decimal
        numeric_types = (int, float, long, Decimal) if USING_PYTHON2 else (int, float, Decimal)  # noqa
        if not isinstance(self._subject, numeric_types):
            raise self._error_factory(_format("Expected {} to be numeric (int, float, long or Decimal)", self._subject))
282723
def _ConvertInteger(value):
  
  if isinstance(value, float) and not value.is_integer():
    raise ParseError('Couldn\'t parse integer: {0}.'.format(value))

  if isinstance(value, six.text_type) and value.find(' ') != -1:
    raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))

  return int(value)
512507
def safe_int(val, default=None):
    

    try:
        val = int(val)
    except (ValueError, TypeError):
        val = default

    return val
1361134
def is_number(dtype):
    """"""
    return is_float(dtype) or ('int' in dtype.name) or ('long' in dtype.name) \
           or ('short' in dtype.name)
507476
def value_to_python(self, value):
        
        if not isinstance(value, bytes):
            raise tldap.exceptions.ValidationError("should be bytes")
        if value is None:
            return value
        try:
            return int(value)
        except (TypeError, ValueError):
            raise tldap.exceptions.ValidationError("is invalid integer")
23385
def _cast_to_type(self, value):
        
        if value in (True, False):
            return bool(value)
        if value in ('t', 'True', '1'):
            return True
        if value in ('f', 'False', '0'):
            return False
        self.fail('invalid', value=value)
539936
def astype(value, types=None):
    
    if types is None:
        types = int, float, asbool, bytes2str
    for typ in types:
        try:
            return typ(value)
        except (ValueError, AttributeError, TypeError, UnicodeEncodeError):
            pass
    return value
163676
def __try_parse_number(self, string):
        """"""
        try:
            return int(string)
        except ValueError:
            try:
                return float(string)
            except ValueError:
                return False
702392
def _isnumber(string):
    
    if not _isconvertible(float, string):
        return False
    elif isinstance(string, (_text_type, _binary_type)) and (
            math.isinf(float(string)) or math.isnan(float(string))):
        return string.lower() in ['inf', '-inf', 'nan']
    return True
593045
def _cast_to_type(self, value):
        
        try:
            return float(value)
        except (ValueError, TypeError):
            self.fail('invalid', value=value)
939276
def _safe_type(value):
    """"""

    if type(value) is str: dtype = 'string'
    if type(value) is unicode: dtype = 'string'
    if type(value) is int: dtype = 'integer'
    if type(value) is float: dtype = 'real'

    return dtype
1244641
def safe_int(string, default=None):
    
    value = safe_float(string, default)
    if value is not None:
        value = int(value)
    return value