File size: 3,248 Bytes
9ff4bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs
# Based on "crates/build/re_type_definitions/rerun/components/entry_kind.def.rs".

# You can extend this class by creating a "EntryKindExt" class in "entry_kind_ext.py".

from __future__ import annotations

from collections.abc import Sequence
from typing import Literal

import pyarrow as pa

from .._baseclasses import (
    BaseBatch,
    ComponentBatchMixin,
)

__all__ = ["EntryKind", "EntryKindArrayLike", "EntryKindBatch", "EntryKindLike"]


from enum import Enum


class EntryKind(Enum):
    """
    **Component**: The kind of a catalog entry.

    The values match those of `rerun.cloud.v1alpha1.EntryKind`.

    ⚠️ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
    """

    Dataset = 1
    """A dataset."""

    DatasetView = 2
    """A view over a dataset."""

    Table = 3
    """A table."""

    TableView = 4
    """A view over a table."""

    BlueprintDataset = 5
    """A dataset holding the blueprints of another entry."""

    AssetDataset = 6
    """A dataset holding the static assets shared by the segments of another dataset."""

    @classmethod
    def auto(cls, val: str | int | EntryKind) -> EntryKind:
        """Best-effort converter, including a case-insensitive string matcher."""
        if isinstance(val, EntryKind):
            return val
        if isinstance(val, int):
            return cls(val)
        try:
            return cls[val]
        except KeyError:
            val_lower = val.lower()
            for variant in cls:
                if variant.name.lower() == val_lower:
                    return variant
        raise ValueError(f"Cannot convert {val} to {cls.__name__}")

    def __str__(self) -> str:
        """Returns the variant name."""
        return self.name


EntryKindLike = (
    EntryKind
    | Literal[
        "AssetDataset",
        "BlueprintDataset",
        "Dataset",
        "DatasetView",
        "Table",
        "TableView",
        "assetdataset",
        "blueprintdataset",
        "dataset",
        "datasetview",
        "table",
        "tableview",
    ]
    | int
)
"""A type alias for any EntryKind-like object."""

EntryKindArrayLike = (
    EntryKind
    | Literal[
        "AssetDataset",
        "BlueprintDataset",
        "Dataset",
        "DatasetView",
        "Table",
        "TableView",
        "assetdataset",
        "blueprintdataset",
        "dataset",
        "datasetview",
        "table",
        "tableview",
    ]
    | int
    | Sequence[EntryKindLike]
)
"""A type alias for any EntryKind-like array object."""


class EntryKindBatch(BaseBatch[EntryKindArrayLike], ComponentBatchMixin):
    _ARROW_DATATYPE = pa.uint8()
    _COMPONENT_TYPE: str = "rerun.components.EntryKind"

    @staticmethod
    def _native_to_pa_array(data: EntryKindArrayLike, data_type: pa.DataType) -> pa.Array:
        items: Sequence[EntryKindLike | str] = [data] if isinstance(data, (EntryKind, int, str)) else data

        pa_data = [EntryKind.auto(v).value if v is not None else None for v in items]  # type: ignore[redundant-expr]

        return pa.array(pa_data, type=data_type)