Skip to content

integer

An Evidence instance for a scalar, integral value.

Integer

Bases: Evidence

Integer implements the Value interface for a single integer value.

Source code in mlte/evidence/types/integer.py
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
class Integer(Evidence):
    """
    Integer implements the Value interface for a single integer value.
    """

    def __init__(self, value: int, unit: Optional[Unit] = None):
        """
        Initialize an Integer instance.
        :param value: The integer value
        :param unit: The unit the values comes in, as a value from Units, defaults to None.
        """
        assert isinstance(value, int), "Argument must be `int`."
        super().__init__()

        self.value = value
        """The wrapped integer value."""

        self.unit = unit
        """The unit, if any."""

    def get_value_w_units(self) -> Quantity:  # type: ignore[type-arg]
        """
        Returns the int value as a Quantity, potentially with units.
        """
        return Quantity(self.value, self.unit)

    def to_model(self) -> ArtifactModel:
        """
        Convert an integer value artifact to its corresponding model.
        :return: The artifact model
        """
        return self._to_artifact_model(
            value_model=IntegerValueModel(
                integer=self.value, unit=unit_to_str(self.unit)
            )
        )

    @classmethod
    def from_model(cls, model: BaseModel) -> Integer:
        """
        Convert an integer value model to its corresponding artifact.
        :param model: The model representation
        :return: The integer value
        """
        body = cls._check_proper_types(model, EvidenceType.INTEGER)
        return Integer(
            value=body.value.integer,  # type: ignore
            unit=str_to_unit(body.value.unit),  # type: ignore
        ).with_metadata(body.metadata)

    def __eq__(self, other: object) -> bool:
        """Comparison between Integer values."""
        if not isinstance(other, Integer):
            return False
        return self._equal(other)

    def __str__(self) -> str:
        """Return a string representation of this Evidence."""
        return f"{self.get_value_w_units() if self.unit else self.value}"

    @classmethod
    def less_than(
        cls,
        threshold: int,
        unit: Optional[Unit] = None,
        success: str = "",
        failure: str = "",
    ) -> Validator:
        """
        Determine if integer is strictly less than `value`.

        :param threshold: The threshold value
        :param unit: the unit the values comes in, as a value from Units
        :return: The Validator that can be used to validate Evidence.
        """
        threshold_w_unit = Quantity(threshold, unit)
        bool_exp: Callable[[Integer], bool] = (
            lambda integer: integer.get_value_w_units() < threshold_w_unit
        )
        validator: Validator = Validator.build_validator(
            bool_exp=bool_exp,
            thresholds=[threshold_w_unit],
            success=success,
            failure=failure,
            default_success=f"Integer magnitude is less than threshold {quantity_to_str(threshold_w_unit)})",
            default_failure=f"Integer magnitude exceeds threshold {quantity_to_str(threshold_w_unit)}",
            input_types=[Integer],
        )
        return validator

    @classmethod
    def less_or_equal_to(
        cls,
        threshold: int,
        unit: Optional[Unit] = None,
        success: str = "",
        failure: str = "",
    ) -> Validator:
        """
        Determine if integer is less than or equal to `value`.

        :param threshold: The threshold value
        :param unit: the unit the values comes in, as a value from Units
        :return: The Validator that can be used to validate Evidence.
        """
        threshold_w_unit = Quantity(threshold, unit)
        bool_exp: Callable[[Integer], bool] = (
            lambda integer: integer.get_value_w_units() <= threshold_w_unit
        )
        validator: Validator = Validator.build_validator(
            bool_exp=bool_exp,
            thresholds=[threshold_w_unit],
            success=success,
            failure=failure,
            default_success=f"Integer magnitude is less than or equal to threshold {quantity_to_str(threshold_w_unit)}",
            default_failure=f"Integer magnitude exceeds threshold {quantity_to_str(threshold_w_unit)}",
            input_types=[Integer],
        )
        return validator

    # Overriden.
    @classmethod
    def load(cls, identifier: typing.Optional[str] = None) -> Integer:
        evidence = super().load(identifier)
        return typing.cast(Integer, evidence)

unit = unit instance-attribute

The unit, if any.

value = value instance-attribute

The wrapped integer value.

__eq__(other)

Comparison between Integer values.

Source code in mlte/evidence/types/integer.py
74
75
76
77
78
def __eq__(self, other: object) -> bool:
    """Comparison between Integer values."""
    if not isinstance(other, Integer):
        return False
    return self._equal(other)

__init__(value, unit=None)

Initialize an Integer instance.

Parameters:

Name Type Description Default
value int

The integer value

required
unit Optional[Unit]

The unit the values comes in, as a value from Units, defaults to None.

None
Source code in mlte/evidence/types/integer.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def __init__(self, value: int, unit: Optional[Unit] = None):
    """
    Initialize an Integer instance.
    :param value: The integer value
    :param unit: The unit the values comes in, as a value from Units, defaults to None.
    """
    assert isinstance(value, int), "Argument must be `int`."
    super().__init__()

    self.value = value
    """The wrapped integer value."""

    self.unit = unit
    """The unit, if any."""

__str__()

Return a string representation of this Evidence.

Source code in mlte/evidence/types/integer.py
80
81
82
def __str__(self) -> str:
    """Return a string representation of this Evidence."""
    return f"{self.get_value_w_units() if self.unit else self.value}"

from_model(model) classmethod

Convert an integer value model to its corresponding artifact.

Parameters:

Name Type Description Default
model BaseModel

The model representation

required

Returns:

Type Description
Integer

The integer value

Source code in mlte/evidence/types/integer.py
61
62
63
64
65
66
67
68
69
70
71
72
@classmethod
def from_model(cls, model: BaseModel) -> Integer:
    """
    Convert an integer value model to its corresponding artifact.
    :param model: The model representation
    :return: The integer value
    """
    body = cls._check_proper_types(model, EvidenceType.INTEGER)
    return Integer(
        value=body.value.integer,  # type: ignore
        unit=str_to_unit(body.value.unit),  # type: ignore
    ).with_metadata(body.metadata)

get_value_w_units()

Returns the int value as a Quantity, potentially with units.

Source code in mlte/evidence/types/integer.py
44
45
46
47
48
def get_value_w_units(self) -> Quantity:  # type: ignore[type-arg]
    """
    Returns the int value as a Quantity, potentially with units.
    """
    return Quantity(self.value, self.unit)

less_or_equal_to(threshold, unit=None, success='', failure='') classmethod

Determine if integer is less than or equal to value.

Parameters:

Name Type Description Default
threshold int

The threshold value

required
unit Optional[Unit]

the unit the values comes in, as a value from Units

None

Returns:

Type Description
Validator

The Validator that can be used to validate Evidence.

Source code in mlte/evidence/types/integer.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@classmethod
def less_or_equal_to(
    cls,
    threshold: int,
    unit: Optional[Unit] = None,
    success: str = "",
    failure: str = "",
) -> Validator:
    """
    Determine if integer is less than or equal to `value`.

    :param threshold: The threshold value
    :param unit: the unit the values comes in, as a value from Units
    :return: The Validator that can be used to validate Evidence.
    """
    threshold_w_unit = Quantity(threshold, unit)
    bool_exp: Callable[[Integer], bool] = (
        lambda integer: integer.get_value_w_units() <= threshold_w_unit
    )
    validator: Validator = Validator.build_validator(
        bool_exp=bool_exp,
        thresholds=[threshold_w_unit],
        success=success,
        failure=failure,
        default_success=f"Integer magnitude is less than or equal to threshold {quantity_to_str(threshold_w_unit)}",
        default_failure=f"Integer magnitude exceeds threshold {quantity_to_str(threshold_w_unit)}",
        input_types=[Integer],
    )
    return validator

less_than(threshold, unit=None, success='', failure='') classmethod

Determine if integer is strictly less than value.

Parameters:

Name Type Description Default
threshold int

The threshold value

required
unit Optional[Unit]

the unit the values comes in, as a value from Units

None

Returns:

Type Description
Validator

The Validator that can be used to validate Evidence.

Source code in mlte/evidence/types/integer.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
@classmethod
def less_than(
    cls,
    threshold: int,
    unit: Optional[Unit] = None,
    success: str = "",
    failure: str = "",
) -> Validator:
    """
    Determine if integer is strictly less than `value`.

    :param threshold: The threshold value
    :param unit: the unit the values comes in, as a value from Units
    :return: The Validator that can be used to validate Evidence.
    """
    threshold_w_unit = Quantity(threshold, unit)
    bool_exp: Callable[[Integer], bool] = (
        lambda integer: integer.get_value_w_units() < threshold_w_unit
    )
    validator: Validator = Validator.build_validator(
        bool_exp=bool_exp,
        thresholds=[threshold_w_unit],
        success=success,
        failure=failure,
        default_success=f"Integer magnitude is less than threshold {quantity_to_str(threshold_w_unit)})",
        default_failure=f"Integer magnitude exceeds threshold {quantity_to_str(threshold_w_unit)}",
        input_types=[Integer],
    )
    return validator

to_model()

Convert an integer value artifact to its corresponding model.

Returns:

Type Description
ArtifactModel

The artifact model

Source code in mlte/evidence/types/integer.py
50
51
52
53
54
55
56
57
58
59
def to_model(self) -> ArtifactModel:
    """
    Convert an integer value artifact to its corresponding model.
    :return: The artifact model
    """
    return self._to_artifact_model(
        value_model=IntegerValueModel(
            integer=self.value, unit=unit_to_str(self.unit)
        )
    )