Convert self value.
339035
def convert(self, value):
        """"""
        try:
            return convert_to_format(value, self._format)
        except (ValueError, TypeError):
            return value
980221
def to_si(self, values, from_unit):
        """"""
        if from_unit in self.si_units:
            return values, from_unit
        elif from_unit == 'ton':
            return self.to_unit(values, 'tonne', from_unit), 'tonne'
        else:
            return self.to_unit(values, 'kg', from_unit), 'kg'
773417
def __to_float(val, digits):
    """"""
    try:
        return round(float(val), digits)
    except (ValueError, TypeError):
        return float(0)
846049
def _convert_value(value):
    """"""
    try:
        return restore(ast.literal_eval(value))
    except (ValueError, SyntaxError):
        if SETTINGS.COMMAND_LINE.STRICT_PARSING:
            raise
        # use as string if nothing else worked
        return value
541057
def convert_column(self, values):
        """"""
        assert all(values >= 0), 'Cannot normalize a column with negatives'
        total = sum(values)
        if total > 0:
            return values / total
        else:
            return values
182335
def to_native(self, value):
        """"""
        if isinstance(value, six.string_types):
            value_list = value.split(self.string_delim)
        else:
            value_list = value

        to_native = self.member_type.to_native if self.member_type is not None else lambda x: x
        return [to_native(item) for item in value_list]
1137339
def to_python(self, value):
        """"""
        if value is None or value == '':
            return value
        if isinstance(value, base.Version):
            return value
        if self.coerce:
            return base.Version.coerce(value, partial=self.partial)
        else:
            return base.Version(value, partial=self.partial)
1052236
def python_value(self, dtype, dvalue):
        """"""
        try:
            return CONVERTERS[dtype](dvalue)
        except KeyError:
            if dtype == clips.common.CLIPSType.MULTIFIELD:
                return self.multifield_to_list()
            if dtype == clips.common.CLIPSType.FACT_ADDRESS:
                return clips.facts.new_fact(self._env, lib.to_pointer(dvalue))
            if dtype == clips.common.CLIPSType.INSTANCE_ADDRESS:
                return clips.classes.Instance(self._env, lib.to_pointer(dvalue))

        return None
1098619
def native(self, value, context=None):
		""""""
		
		separator = self.separator.strip() if self.strip and hasattr(self.separator, 'strip') else self.separator
		value = super().native(value, context)
		
		if value is None:
			return self.cast()
		
		if hasattr(value, 'split'):
			value = value.split(separator)
		
		value = self._clean(value)
		
		try:
			return self.cast(value) if self.cast else value
		except Exception as e:
			raise Concern("{0} caught, failed to perform array transform: {1}", e.__class__.__name__, str(e))
1203087
def to_si(self, values, from_unit):
        """"""
        if from_unit in self._si_units:
            return values, from_unit
        elif from_unit == 'degF-hours':
            return self.to_unit(values, 'degC-hours', from_unit), 'degC-hours'
        else:
            return self.to_unit(values, 'degC-days', from_unit), 'degC-days'
18171
def to_primitive(self, value, context=None):
        

        if context and context.get('epoch_date'):
            epoch = dt(1970, 1, 1)
            value = (value - epoch).total_seconds()
            return int(value)
        elif context and context.get('datetime_date'):
            return value
        else:
            return super(Type, self).to_primitive(value, context)
115277
def _convert_number(self, number):
        """"""

        number = float(number)
        return int(number) if number.is_integer() else float(number)
1328738
def tovalue(self, fmt='Q'):
        '''
        
        '''
        format_size = struct.calcsize(fmt)
        if self.length() > format_size * 8:
            raise TypeError('Cannot convert to number')
        ba = self.copy()
        ba.extend((format_size * 8 - self.length()) * [0])
        return struct.unpack_from(fmt, ba.tobytes())[0]
46196
def convert_to_unit(self, unit):
        """"""
        self._values = self._header.data_type.to_unit(
            self._values, unit, self._header.unit)
        self._header._unit = unit
78370
def value_convert(self, value, value_type):
        
        CONVERSION_OPTIONS = {
            "str": str,
            "int": int,
            "float": float,
            # Treat booleans specially
            "bool": (lambda val: val.lower() in ("true", "1")),
            # Auto-guess the type
            "auto": self.make_value,
        }

        try:
            return CONVERSION_OPTIONS[value_type](value)
        except (TypeError, ValueError):
            self.notify_user("Bad type conversion")
            return None
406828
def process_result_value(self, value, dialect):
        """"""
        if value is not None:
            with BytesIO(value) as stream:
                with GzipFile(fileobj=stream, mode="rb") as file_handle:
                    value = json.loads(file_handle.read().decode("utf-8"))
        return value
585929
def value(self, data):
        """"""
        value = data.get(self.name)
        if value:
            return int(value)
        return self.default