MCPcopy Create free account
hub / github.com/apple/coremltools / _ConvertInteger

Function _ConvertInteger

deps/protobuf/python/google/protobuf/json_format.py:755–777  ·  view source on GitHub ↗

Convert an integer. Args: value: A scalar value to convert. Returns: The integer value. Raises: ParseError: If an integer couldn't be consumed.

(value)

Source from the content-addressed store, hash-verified

753
754
755def _ConvertInteger(value):
756 """Convert an integer.
757
758 Args:
759 value: A scalar value to convert.
760
761 Returns:
762 The integer value.
763
764 Raises:
765 ParseError: If an integer couldn't be consumed.
766 """
767 if isinstance(value, float) and not value.is_integer():
768 raise ParseError('Couldn\'t parse integer: {0}.'.format(value))
769
770 if isinstance(value, str) and value.find(' ') != -1:
771 raise ParseError('Couldn\'t parse integer: "{0}".'.format(value))
772
773 if isinstance(value, bool):
774 raise ParseError('Bool value {0} is not acceptable for '
775 'integer field.'.format(value))
776
777 return int(value)
778
779
780def _ConvertFloat(value, field):

Callers 1

_ConvertScalarFieldValueFunction · 0.85

Calls 5

isinstanceFunction · 0.85
intClass · 0.85
ParseErrorClass · 0.70
formatMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected