Skip to content

type_bridge.attribute.double

double

Double attribute type for TypeDB.

Double

Double(value)

Bases: NumericAttribute

Double precision float attribute type that accepts float values.

Example

class Price(Double): pass

class Score(Double): pass

Initialize Double attribute with a float value.

Parameters:

Name Type Description Default
value float

The float value to store

required

Raises:

Type Description
ValueError

If value violates range_constraint

Source code in type_bridge/attribute/double.py
def __init__(self, value: float):
    """Initialize Double attribute with a float value.

    Args:
        value: The float value to store

    Raises:
        ValueError: If value violates range_constraint
    """
    float_value = float(value)

    # Check range constraint if defined on the class
    range_constraint = getattr(self.__class__, "range_constraint", None)
    if range_constraint is not None:
        range_min, range_max = range_constraint
        if range_min is not None:
            min_val = float(range_min)
            if float_value < min_val:
                raise ValueError(
                    f"{self.__class__.__name__} value {float_value} is below minimum {min_val}"
                )
        if range_max is not None:
            max_val = float(range_max)
            if float_value > max_val:
                raise ValueError(
                    f"{self.__class__.__name__} value {float_value} is above maximum {max_val}"
                )

    super().__init__(float_value)

value property

value

Get the stored float value.

__float__

__float__()

Convert to float.

Source code in type_bridge/attribute/double.py
def __float__(self) -> float:
    """Convert to float."""
    return float(self.value)