Skip to content

array

Implementation of Array Evidence.

Array

Bases: Evidence

Array implements the Evidence interface for an array of values.

Source code in mlte/evidence/types/array.py
16
17
18
19
20
21
22
23
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
class Array(Evidence):
    """
    Array implements the Evidence interface for an array of values.
    """

    def __init__(self, array: list[Any]):
        """
        Initialize an Array instance.
        :param array: The array.
        """
        super().__init__()

        self.array: list[Any] = array
        """Underlying values represented as an array."""

    def to_model(self) -> ArtifactModel:
        """
        Convert an array value artifact to its corresponding model.
        :return: The artifact model
        """
        return self._to_artifact_model(
            value_model=ArrayValueModel(data=self.array)
        )

    @classmethod
    def from_model(cls, model: BaseModel) -> Array:
        """
        Convert an array value model to its corresponding artifact.
        :param model: The model representation
        :return: The array value
        """
        body = cls._check_proper_types(model, EvidenceType.ARRAY)
        return Array(array=body.value.data).with_metadata(body.metadata)  # type: ignore

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

    def __str__(self) -> str:
        return str(self.array)

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

array = array instance-attribute

Underlying values represented as an array.

__eq__(other)

Comparison between Array values.

Source code in mlte/evidence/types/array.py
59
60
61
62
63
def __eq__(self, other: object) -> bool:
    """Comparison between Array values."""
    if not isinstance(other, Array):
        return False
    return self._equal(other)

__init__(array)

Initialize an Array instance.

Parameters:

Name Type Description Default
array list[Any]

The array.

required
Source code in mlte/evidence/types/array.py
21
22
23
24
25
26
27
28
29
def __init__(self, array: list[Any]):
    """
    Initialize an Array instance.
    :param array: The array.
    """
    super().__init__()

    self.array: list[Any] = array
    """Underlying values represented as an array."""

from_model(model) classmethod

Convert an array value model to its corresponding artifact.

Parameters:

Name Type Description Default
model BaseModel

The model representation

required

Returns:

Type Description
Array

The array value

Source code in mlte/evidence/types/array.py
40
41
42
43
44
45
46
47
48
@classmethod
def from_model(cls, model: BaseModel) -> Array:
    """
    Convert an array value model to its corresponding artifact.
    :param model: The model representation
    :return: The array value
    """
    body = cls._check_proper_types(model, EvidenceType.ARRAY)
    return Array(array=body.value.data).with_metadata(body.metadata)  # type: ignore

to_model()

Convert an array value artifact to its corresponding model.

Returns:

Type Description
ArtifactModel

The artifact model

Source code in mlte/evidence/types/array.py
31
32
33
34
35
36
37
38
def to_model(self) -> ArtifactModel:
    """
    Convert an array value artifact to its corresponding model.
    :return: The artifact model
    """
    return self._to_artifact_model(
        value_model=ArrayValueModel(data=self.array)
    )