File size: 2,765 Bytes
2c3c408
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import io

import numpy as np

import tiledb.cc as lt

from .ctx import CtxMixin
from .data_order import DataOrder
from .datatypes import DataType


class DimLabel(CtxMixin, lt.DimensionLabel):
    """
    Represents a TileDB dimension label.
    """

    def __repr__(self) -> str:
        dtype = "ascii" if self.isascii else self.dtype
        return (
            f"DimLabel(name={self.name}, dtype='{dtype!s}', "
            f"var={self.isvar!s}, order={self.order!s})"
        )

    def _repr_html_(self):
        output = io.StringIO()

        output.write("<table>")
        output.write("<tr>")
        output.write("<th>Name</th>")
        output.write("<th>Data Type</th>")
        output.write("<th>Is Var-Len</th>")
        output.write("<th>Data Order</th>")
        output.write("</tr>")
        output.write(f"{self._repr_html_row_only_()}")
        output.write("</table>")

        return output.getvalue()

    def _repr_html_row_only_(self):
        output = io.StringIO()

        output.write("<tr>")
        output.write(f"<td>{self.name}</td>")
        output.write(f"<td>{'ascii' if self.isascii else self.dtype}</td>")
        output.write(f"<td>{self.isvar}</td>")
        output.write(f"<td>{self.order}</td>")
        output.write("</tr>")

        return output.getvalue()

    @property
    def dim_index(self) -> int:
        """Index of the dimension the labels are for.

        :rtype: int

        """
        return self._dim_index

    @property
    def dtype(self) -> np.dtype:
        """Numpy dtype representation of the label type.

        :rtype: numpy.dtype

        """
        return DataType.from_tiledb(self._tiledb_label_dtype).np_dtype

    @property
    def isvar(self) -> bool:
        """True if the labels are variable length.

        :rtype: bool

        """
        return self._label_ncell == lt.TILEDB_VAR_NUM()

    @property
    def isascii(self) -> bool:
        """True if the labels are variable length.

        :rtype: bool

        """
        return self._tiledb_label_dtype == lt.DataType.STRING_ASCII

    @property
    def label_attr_name(self) -> str:
        """Name of the attribute storing the label data.

        :rtype: str
        """
        return self._label_attr_name

    @property
    def name(self) -> str:
        """The name of the dimension label.

        :rtype: str

        """
        return self._name

    @property
    def order(self) -> str:
        """The order of the label data in the dimension label.

        :rtype: str
        """
        return DataOrder(self._tiledb_label_order).name

    @property
    def uri(self) -> str:
        """The URI of the array containing the dimension label data.

        :rtype: str

        """
        return self._uri