dtypeflow 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dtypeflow/__init__.py +5 -0
- dtypeflow/core/__init__.py +1 -0
- dtypeflow/core/candidate/__init__.py +40 -0
- dtypeflow/core/candidate/base.py +37 -0
- dtypeflow/core/candidate/factory.py +258 -0
- dtypeflow/core/candidate/primitive.py +79 -0
- dtypeflow/core/dataset.py +46 -0
- dtypeflow/core/dtype/__init__.py +70 -0
- dtypeflow/core/dtype/base.py +14 -0
- dtypeflow/core/dtype/hierachy.md +51 -0
- dtypeflow/core/dtype/nested/__init__.py +5 -0
- dtypeflow/core/dtype/nested/dictionary.py +14 -0
- dtypeflow/core/dtype/primitive/__init__.py +39 -0
- dtypeflow/core/dtype/primitive/base.py +6 -0
- dtypeflow/core/dtype/primitive/boolean.py +20 -0
- dtypeflow/core/dtype/primitive/float.py +40 -0
- dtypeflow/core/dtype/primitive/integer/__init__.py +31 -0
- dtypeflow/core/dtype/primitive/integer/base.py +17 -0
- dtypeflow/core/dtype/primitive/integer/signed.py +37 -0
- dtypeflow/core/dtype/primitive/integer/unsigned.py +37 -0
- dtypeflow/core/dtype/primitive/string.py +14 -0
- dtypeflow/core/override/__init__.py +41 -0
- dtypeflow/core/override/base.py +22 -0
- dtypeflow/core/override/primitive.py +158 -0
- dtypeflow/core/profile/__init__.py +39 -0
- dtypeflow/core/profile/base.py +50 -0
- dtypeflow/core/profile/primitive.py +166 -0
- dtypeflow/core/profiler.py +169 -0
- dtypeflow/core/schema.py +33 -0
- dtypeflow/core/table.py +29 -0
- dtypeflow/py.typed +0 -0
- dtypeflow/tui/__init__.py +17 -0
- dtypeflow/tui/app.py +747 -0
- dtypeflow/tui/app.tcss +220 -0
- dtypeflow/tui/compatibility.py +38 -0
- dtypeflow/tui/dto.py +44 -0
- dtypeflow/tui/service.py +213 -0
- dtypeflow/utils.py +32 -0
- dtypeflow-1.0.0.dist-info/METADATA +93 -0
- dtypeflow-1.0.0.dist-info/RECORD +43 -0
- dtypeflow-1.0.0.dist-info/WHEEL +4 -0
- dtypeflow-1.0.0.dist-info/entry_points.txt +3 -0
- dtypeflow-1.0.0.dist-info/licenses/LICENSE +21 -0
dtypeflow/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .base import Candidate, Compatibility
|
|
4
|
+
from .factory import candidate_factory
|
|
5
|
+
from .primitive import (
|
|
6
|
+
Boolean as BooleanCandidate,
|
|
7
|
+
Dictionary as DictionaryCandidate,
|
|
8
|
+
Float16 as Float16Candidate,
|
|
9
|
+
Float32 as Float32Candidate,
|
|
10
|
+
Float64 as Float64Candidate,
|
|
11
|
+
Int8 as Int8Candidate,
|
|
12
|
+
Int16 as Int16Candidate,
|
|
13
|
+
Int32 as Int32Candidate,
|
|
14
|
+
Int64 as Int64Candidate,
|
|
15
|
+
String as StringCandidate,
|
|
16
|
+
UInt8 as UInt8Candidate,
|
|
17
|
+
UInt16 as UInt16Candidate,
|
|
18
|
+
UInt32 as UInt32Candidate,
|
|
19
|
+
UInt64 as UInt64Candidate,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__: list[str] = [
|
|
23
|
+
"BooleanCandidate",
|
|
24
|
+
"Candidate",
|
|
25
|
+
"Compatibility",
|
|
26
|
+
"DictionaryCandidate",
|
|
27
|
+
"Float16Candidate",
|
|
28
|
+
"Float32Candidate",
|
|
29
|
+
"Float64Candidate",
|
|
30
|
+
"Int8Candidate",
|
|
31
|
+
"Int16Candidate",
|
|
32
|
+
"Int32Candidate",
|
|
33
|
+
"Int64Candidate",
|
|
34
|
+
"StringCandidate",
|
|
35
|
+
"UInt8Candidate",
|
|
36
|
+
"UInt16Candidate",
|
|
37
|
+
"UInt32Candidate",
|
|
38
|
+
"UInt64Candidate",
|
|
39
|
+
"candidate_factory",
|
|
40
|
+
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC
|
|
4
|
+
from enum import Enum, auto
|
|
5
|
+
from typing import TYPE_CHECKING, ClassVar
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from dtypeflow.core.dtype import Dtype
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Compatibility(Enum):
|
|
12
|
+
FULL_RANGE_FIT = auto()
|
|
13
|
+
VALUES_PRESERVED = auto()
|
|
14
|
+
VALUES_NO_FIT = auto()
|
|
15
|
+
RANGE_NO_FIT = auto()
|
|
16
|
+
UNEVALUATED_NO_FIT = auto()
|
|
17
|
+
NOT_NUMERIC = auto()
|
|
18
|
+
OBSERVED_ONLY_FIT = auto()
|
|
19
|
+
DECIMAL_TRUNCATION = auto()
|
|
20
|
+
PRECISION_REDUCTION = auto()
|
|
21
|
+
BOOLEAN_MAPPING = auto()
|
|
22
|
+
DICTIONARY_ENCODING = auto()
|
|
23
|
+
DICTIONARY_INEFFICIENT = auto()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Candidate(ABC):
|
|
27
|
+
DTYPE: ClassVar[type[Dtype]]
|
|
28
|
+
|
|
29
|
+
def __init__(self, compatibility: Compatibility, /) -> None:
|
|
30
|
+
self._compatibility: Compatibility = compatibility
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def compatibility(self) -> Compatibility:
|
|
34
|
+
return self._compatibility
|
|
35
|
+
|
|
36
|
+
def __repr__(self) -> str:
|
|
37
|
+
return f"{type(self).__name__}(compatibility={self._compatibility.name})"
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from typing import Final, overload
|
|
5
|
+
|
|
6
|
+
from dtypeflow.core.dtype import (
|
|
7
|
+
ALL_TYPES,
|
|
8
|
+
BooleanDtype,
|
|
9
|
+
DictionaryDtype,
|
|
10
|
+
Dtype,
|
|
11
|
+
Float16Dtype,
|
|
12
|
+
Float32Dtype,
|
|
13
|
+
Float64Dtype,
|
|
14
|
+
FloatDtype,
|
|
15
|
+
Int8Dtype,
|
|
16
|
+
Int16Dtype,
|
|
17
|
+
Int32Dtype,
|
|
18
|
+
Int64Dtype,
|
|
19
|
+
IntegerDtype,
|
|
20
|
+
StringDtype,
|
|
21
|
+
UInt8Dtype,
|
|
22
|
+
UInt16Dtype,
|
|
23
|
+
UInt32Dtype,
|
|
24
|
+
UInt64Dtype,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
from .base import Candidate, Compatibility
|
|
28
|
+
from .primitive import (
|
|
29
|
+
Boolean as BooleanCandidate,
|
|
30
|
+
Dictionary as DictionaryCandidate,
|
|
31
|
+
Float16 as Float16Candidate,
|
|
32
|
+
Float32 as Float32Candidate,
|
|
33
|
+
Float64 as Float64Candidate,
|
|
34
|
+
Int8 as Int8Candidate,
|
|
35
|
+
Int16 as Int16Candidate,
|
|
36
|
+
Int32 as Int32Candidate,
|
|
37
|
+
Int64 as Int64Candidate,
|
|
38
|
+
String as StringCandidate,
|
|
39
|
+
UInt8 as UInt8Candidate,
|
|
40
|
+
UInt16 as UInt16Candidate,
|
|
41
|
+
UInt32 as UInt32Candidate,
|
|
42
|
+
UInt64 as UInt64Candidate,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
_MAX_BOOLEAN_UNIQUE: Final[int] = 2
|
|
46
|
+
_MAX_DICTIONARY_ABSOLUTE: Final[int] = 20
|
|
47
|
+
_MAX_DICTIONARY_RATIO: Final[float] = 0.05
|
|
48
|
+
_CANDIDATE_MAPPER: Final[dict[type[Dtype], type[Candidate]]] = {
|
|
49
|
+
BooleanDtype: BooleanCandidate,
|
|
50
|
+
UInt8Dtype: UInt8Candidate,
|
|
51
|
+
UInt16Dtype: UInt16Candidate,
|
|
52
|
+
UInt32Dtype: UInt32Candidate,
|
|
53
|
+
UInt64Dtype: UInt64Candidate,
|
|
54
|
+
Int8Dtype: Int8Candidate,
|
|
55
|
+
Int16Dtype: Int16Candidate,
|
|
56
|
+
Int32Dtype: Int32Candidate,
|
|
57
|
+
Int64Dtype: Int64Candidate,
|
|
58
|
+
Float16Dtype: Float16Candidate,
|
|
59
|
+
Float32Dtype: Float32Candidate,
|
|
60
|
+
Float64Dtype: Float64Candidate,
|
|
61
|
+
StringDtype: StringCandidate,
|
|
62
|
+
DictionaryDtype: DictionaryCandidate,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _full_bounds(dtype: type[Dtype], /) -> tuple[Decimal, Decimal] | None:
|
|
67
|
+
if issubclass(dtype, BooleanDtype):
|
|
68
|
+
return (Decimal(0), Decimal(1))
|
|
69
|
+
if issubclass(dtype, IntegerDtype):
|
|
70
|
+
return (Decimal(dtype.LOWER_BOUND), Decimal(dtype.HIGHER_BOUND))
|
|
71
|
+
if issubclass(dtype, FloatDtype):
|
|
72
|
+
return (-dtype.MAX_ABSOLUTE_VALUE, dtype.MAX_ABSOLUTE_VALUE)
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _full_precision(dtype: type[Dtype], /) -> int:
|
|
77
|
+
if issubclass(dtype, FloatDtype):
|
|
78
|
+
return dtype.MAX_SIGNIFICANT_DIGITS
|
|
79
|
+
bounds: tuple[Decimal, Decimal] | None = _full_bounds(dtype)
|
|
80
|
+
if bounds is None:
|
|
81
|
+
return 0
|
|
82
|
+
return len(str(int(max(abs(bounds[0]), abs(bounds[1])))))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _boolean_compatibility(num_unique: int | None, /) -> Compatibility:
|
|
86
|
+
if num_unique is not None and num_unique <= _MAX_BOOLEAN_UNIQUE:
|
|
87
|
+
return Compatibility.BOOLEAN_MAPPING
|
|
88
|
+
return Compatibility.VALUES_NO_FIT
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _dictionary_compatibility(
|
|
92
|
+
num_unique: int | None, total: int | None, /,
|
|
93
|
+
) -> Compatibility:
|
|
94
|
+
eligible: bool = num_unique is not None and (
|
|
95
|
+
num_unique <= _MAX_DICTIONARY_ABSOLUTE
|
|
96
|
+
or (
|
|
97
|
+
total is not None
|
|
98
|
+
and total > 0
|
|
99
|
+
and (num_unique / total <= _MAX_DICTIONARY_RATIO)
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
if not eligible:
|
|
103
|
+
return Compatibility.DICTIONARY_INEFFICIENT
|
|
104
|
+
return Compatibility.DICTIONARY_ENCODING
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _fits_full_range(source: type[Dtype], target: type[Dtype], /) -> bool:
|
|
108
|
+
source_bounds: tuple[Decimal, Decimal] | None = _full_bounds(source)
|
|
109
|
+
target_bounds: tuple[Decimal, Decimal] | None = _full_bounds(target)
|
|
110
|
+
return (
|
|
111
|
+
source_bounds is not None
|
|
112
|
+
and target_bounds is not None
|
|
113
|
+
and (target_bounds[0] <= source_bounds[0])
|
|
114
|
+
and (source_bounds[1] <= target_bounds[1])
|
|
115
|
+
and (
|
|
116
|
+
not issubclass(target, FloatDtype)
|
|
117
|
+
or _full_precision(source) <= target.MAX_SIGNIFICANT_DIGITS
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _exceeds_precision(
|
|
123
|
+
target: type[FloatDtype],
|
|
124
|
+
min_value: int | Decimal,
|
|
125
|
+
max_value: int | Decimal,
|
|
126
|
+
precision: int | None,
|
|
127
|
+
/,
|
|
128
|
+
) -> bool:
|
|
129
|
+
if precision is not None:
|
|
130
|
+
observed_precision: int = precision
|
|
131
|
+
else:
|
|
132
|
+
bound: Decimal | int = max(abs(min_value), abs(max_value))
|
|
133
|
+
observed_precision = len(str(int(bound)))
|
|
134
|
+
return observed_precision > target.MAX_SIGNIFICANT_DIGITS
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _unevaluated_compatibility(*, full_range_fits: bool) -> Compatibility:
|
|
138
|
+
if full_range_fits:
|
|
139
|
+
return Compatibility.FULL_RANGE_FIT
|
|
140
|
+
return Compatibility.UNEVALUATED_NO_FIT
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _observed_compatibility(*, full_range_fits: bool) -> Compatibility:
|
|
144
|
+
if full_range_fits:
|
|
145
|
+
return Compatibility.FULL_RANGE_FIT
|
|
146
|
+
return Compatibility.OBSERVED_ONLY_FIT
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _range_compatibility(
|
|
150
|
+
source: type[Dtype],
|
|
151
|
+
target: type[Dtype],
|
|
152
|
+
/,
|
|
153
|
+
*,
|
|
154
|
+
min_value: int | Decimal | None,
|
|
155
|
+
max_value: int | Decimal | None,
|
|
156
|
+
precision: int | None,
|
|
157
|
+
scale: int | None,
|
|
158
|
+
) -> Compatibility:
|
|
159
|
+
full_range_fits: bool = _fits_full_range(source, target)
|
|
160
|
+
target_bounds: tuple[Decimal, Decimal] | None = _full_bounds(target)
|
|
161
|
+
if min_value is None or max_value is None or target_bounds is None:
|
|
162
|
+
if issubclass(source, StringDtype):
|
|
163
|
+
return Compatibility.NOT_NUMERIC
|
|
164
|
+
return _unevaluated_compatibility(full_range_fits=full_range_fits)
|
|
165
|
+
if issubclass(target, IntegerDtype) and (scale or 0) > 0:
|
|
166
|
+
return Compatibility.DECIMAL_TRUNCATION
|
|
167
|
+
if not (target_bounds[0] <= min_value and max_value <= target_bounds[1]):
|
|
168
|
+
return Compatibility.RANGE_NO_FIT
|
|
169
|
+
if issubclass(target, FloatDtype) and _exceeds_precision(
|
|
170
|
+
target, min_value, max_value, precision,
|
|
171
|
+
):
|
|
172
|
+
return Compatibility.PRECISION_REDUCTION
|
|
173
|
+
return _observed_compatibility(full_range_fits=full_range_fits)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _compatibility(
|
|
177
|
+
source: type[Dtype],
|
|
178
|
+
target: type[Dtype],
|
|
179
|
+
/,
|
|
180
|
+
*,
|
|
181
|
+
num_unique: int | None,
|
|
182
|
+
total: int | None,
|
|
183
|
+
min_value: int | Decimal | None,
|
|
184
|
+
max_value: int | Decimal | None,
|
|
185
|
+
precision: int | None,
|
|
186
|
+
scale: int | None,
|
|
187
|
+
) -> Compatibility:
|
|
188
|
+
if issubclass(target, StringDtype):
|
|
189
|
+
return Compatibility.VALUES_PRESERVED
|
|
190
|
+
if issubclass(target, BooleanDtype):
|
|
191
|
+
return _boolean_compatibility(num_unique)
|
|
192
|
+
if issubclass(target, DictionaryDtype):
|
|
193
|
+
return _dictionary_compatibility(num_unique, total)
|
|
194
|
+
return _range_compatibility(
|
|
195
|
+
source,
|
|
196
|
+
target,
|
|
197
|
+
min_value=min_value,
|
|
198
|
+
max_value=max_value,
|
|
199
|
+
precision=precision,
|
|
200
|
+
scale=scale,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@overload
|
|
205
|
+
def candidate_factory(dtype: type[Dtype], /) -> tuple[Candidate, ...]: ...
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@overload
|
|
209
|
+
def candidate_factory(
|
|
210
|
+
dtype: type[Dtype], /, *, num_unique: int, total: int | None = None,
|
|
211
|
+
) -> tuple[Candidate, ...]: ...
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
@overload
|
|
215
|
+
def candidate_factory(
|
|
216
|
+
dtype: type[Dtype],
|
|
217
|
+
/,
|
|
218
|
+
*,
|
|
219
|
+
num_unique: int,
|
|
220
|
+
total: int | None = None,
|
|
221
|
+
min_value: int | Decimal,
|
|
222
|
+
max_value: int | Decimal,
|
|
223
|
+
precision: int | None = None,
|
|
224
|
+
scale: int | None = None,
|
|
225
|
+
) -> tuple[Candidate, ...]: ...
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def candidate_factory(
|
|
229
|
+
dtype: type[Dtype],
|
|
230
|
+
/,
|
|
231
|
+
*,
|
|
232
|
+
num_unique: int | None = None,
|
|
233
|
+
total: int | None = None,
|
|
234
|
+
min_value: int | Decimal | None = None,
|
|
235
|
+
max_value: int | Decimal | None = None,
|
|
236
|
+
precision: int | None = None,
|
|
237
|
+
scale: int | None = None,
|
|
238
|
+
) -> tuple[Candidate, ...]:
|
|
239
|
+
if dtype not in ALL_TYPES:
|
|
240
|
+
msg = f"Unsupported dtype: {dtype}"
|
|
241
|
+
raise ValueError(msg)
|
|
242
|
+
candidate_dtypes: tuple[type[Dtype], ...] = tuple(
|
|
243
|
+
target for target in ALL_TYPES if target is not dtype
|
|
244
|
+
)
|
|
245
|
+
candidates: list[Candidate] = []
|
|
246
|
+
for target in candidate_dtypes:
|
|
247
|
+
compatibility: Compatibility = _compatibility(
|
|
248
|
+
dtype,
|
|
249
|
+
target,
|
|
250
|
+
num_unique=num_unique,
|
|
251
|
+
total=total,
|
|
252
|
+
min_value=min_value,
|
|
253
|
+
max_value=max_value,
|
|
254
|
+
precision=precision,
|
|
255
|
+
scale=scale,
|
|
256
|
+
)
|
|
257
|
+
candidates.append(_CANDIDATE_MAPPER[target](compatibility))
|
|
258
|
+
return tuple(candidates)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Final
|
|
4
|
+
|
|
5
|
+
from dtypeflow.core.dtype import (
|
|
6
|
+
BooleanDtype,
|
|
7
|
+
DictionaryDtype,
|
|
8
|
+
Dtype,
|
|
9
|
+
Float16Dtype,
|
|
10
|
+
Float32Dtype,
|
|
11
|
+
Float64Dtype,
|
|
12
|
+
Int8Dtype,
|
|
13
|
+
Int16Dtype,
|
|
14
|
+
Int32Dtype,
|
|
15
|
+
Int64Dtype,
|
|
16
|
+
StringDtype,
|
|
17
|
+
UInt8Dtype,
|
|
18
|
+
UInt16Dtype,
|
|
19
|
+
UInt32Dtype,
|
|
20
|
+
UInt64Dtype,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from .base import Candidate
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Boolean(Candidate):
|
|
27
|
+
DTYPE: Final[type[Dtype]] = BooleanDtype
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class UInt8(Candidate):
|
|
31
|
+
DTYPE: Final[type[Dtype]] = UInt8Dtype
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class UInt16(Candidate):
|
|
35
|
+
DTYPE: Final[type[Dtype]] = UInt16Dtype
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class UInt32(Candidate):
|
|
39
|
+
DTYPE: Final[type[Dtype]] = UInt32Dtype
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class UInt64(Candidate):
|
|
43
|
+
DTYPE: Final[type[Dtype]] = UInt64Dtype
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Int8(Candidate):
|
|
47
|
+
DTYPE: Final[type[Dtype]] = Int8Dtype
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Int16(Candidate):
|
|
51
|
+
DTYPE: Final[type[Dtype]] = Int16Dtype
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Int32(Candidate):
|
|
55
|
+
DTYPE: Final[type[Dtype]] = Int32Dtype
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class Int64(Candidate):
|
|
59
|
+
DTYPE: Final[type[Dtype]] = Int64Dtype
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Float16(Candidate):
|
|
63
|
+
DTYPE: Final[type[Dtype]] = Float16Dtype
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class Float32(Candidate):
|
|
67
|
+
DTYPE: Final[type[Dtype]] = Float32Dtype
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Float64(Candidate):
|
|
71
|
+
DTYPE: Final[type[Dtype]] = Float64Dtype
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class String(Candidate):
|
|
75
|
+
DTYPE: Final[type[Dtype]] = StringDtype
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class Dictionary(Candidate):
|
|
79
|
+
DTYPE: Final[type[Dtype]] = DictionaryDtype
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator, Mapping
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from types import MappingProxyType
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from dtypeflow.core.dtype import Dtype
|
|
10
|
+
from dtypeflow.core.profile import Profile
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Dataset(Mapping[str, "Profile"]):
|
|
14
|
+
def __init__(self, source: str | Path, /, **profiles: Profile) -> None:
|
|
15
|
+
if isinstance(source, str):
|
|
16
|
+
source: Path = Path(source)
|
|
17
|
+
self._source: Path = source
|
|
18
|
+
self._profiles: MappingProxyType[str, Profile] = MappingProxyType(profiles)
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def source(self) -> Path:
|
|
22
|
+
return self._source
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def columns(self) -> tuple[str, ...]:
|
|
26
|
+
return tuple(self._profiles.keys())
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def dtypes(self) -> MappingProxyType[str, type[Dtype]]:
|
|
30
|
+
return MappingProxyType(
|
|
31
|
+
{column: profile.DTYPE for (column, profile) in self._profiles.items()},
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def __getitem__(self, column: str) -> Profile:
|
|
35
|
+
return self._profiles[column]
|
|
36
|
+
|
|
37
|
+
def __iter__(self) -> Iterator[str]:
|
|
38
|
+
return iter(self._profiles)
|
|
39
|
+
|
|
40
|
+
def __len__(self) -> int:
|
|
41
|
+
return len(self._profiles)
|
|
42
|
+
|
|
43
|
+
def __repr__(self) -> str:
|
|
44
|
+
return (
|
|
45
|
+
f"{type(self).__name__}(source={self._source!r}, columns={self.columns!r})"
|
|
46
|
+
)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Final
|
|
4
|
+
|
|
5
|
+
from .base import Dtype
|
|
6
|
+
from .nested import DictionaryDtype
|
|
7
|
+
from .primitive import (
|
|
8
|
+
BooleanDtype,
|
|
9
|
+
Float16Dtype,
|
|
10
|
+
Float32Dtype,
|
|
11
|
+
Float64Dtype,
|
|
12
|
+
FloatDtype,
|
|
13
|
+
Int8Dtype,
|
|
14
|
+
Int16Dtype,
|
|
15
|
+
Int32Dtype,
|
|
16
|
+
Int64Dtype,
|
|
17
|
+
IntegerDtype,
|
|
18
|
+
StringDtype,
|
|
19
|
+
UInt8Dtype,
|
|
20
|
+
UInt16Dtype,
|
|
21
|
+
UInt32Dtype,
|
|
22
|
+
UInt64Dtype,
|
|
23
|
+
)
|
|
24
|
+
from .primitive.integer import SignedDtype, UnsignedDtype
|
|
25
|
+
|
|
26
|
+
__all__: list[str] = [
|
|
27
|
+
"ALL_TYPES",
|
|
28
|
+
"BOOLEAN_TYPES",
|
|
29
|
+
"FLOAT_TYPES",
|
|
30
|
+
"INTEGER_TYPES",
|
|
31
|
+
"SIGNED_INTEGER_TYPES",
|
|
32
|
+
"STRING_TYPES",
|
|
33
|
+
"UNSIGNED_INTEGER_TYPES",
|
|
34
|
+
"BooleanDtype",
|
|
35
|
+
"DictionaryDtype",
|
|
36
|
+
"Dtype",
|
|
37
|
+
"Float16Dtype",
|
|
38
|
+
"Float32Dtype",
|
|
39
|
+
"Float64Dtype",
|
|
40
|
+
"FloatDtype",
|
|
41
|
+
"Int8Dtype",
|
|
42
|
+
"Int16Dtype",
|
|
43
|
+
"Int32Dtype",
|
|
44
|
+
"Int64Dtype",
|
|
45
|
+
"IntegerDtype",
|
|
46
|
+
"StringDtype",
|
|
47
|
+
"UInt8Dtype",
|
|
48
|
+
"UInt16Dtype",
|
|
49
|
+
"UInt32Dtype",
|
|
50
|
+
"UInt64Dtype",
|
|
51
|
+
]
|
|
52
|
+
BOOLEAN_TYPES: Final[tuple[type[Dtype], ...]] = (BooleanDtype,)
|
|
53
|
+
UNSIGNED_INTEGER_TYPES: Final[tuple[type[IntegerDtype], ...]] = tuple(
|
|
54
|
+
UnsignedDtype.__subclasses__(),
|
|
55
|
+
)
|
|
56
|
+
SIGNED_INTEGER_TYPES: Final[tuple[type[IntegerDtype], ...]] = tuple(
|
|
57
|
+
SignedDtype.__subclasses__(),
|
|
58
|
+
)
|
|
59
|
+
INTEGER_TYPES: Final[tuple[type[IntegerDtype], ...]] = (
|
|
60
|
+
UNSIGNED_INTEGER_TYPES + SIGNED_INTEGER_TYPES
|
|
61
|
+
)
|
|
62
|
+
FLOAT_TYPES: Final[tuple[type[FloatDtype], ...]] = tuple(FloatDtype.__subclasses__())
|
|
63
|
+
STRING_TYPES: Final[tuple[type[Dtype], ...]] = (StringDtype,)
|
|
64
|
+
ALL_TYPES: Final[tuple[type[Dtype], ...]] = (
|
|
65
|
+
*BOOLEAN_TYPES,
|
|
66
|
+
DictionaryDtype,
|
|
67
|
+
*INTEGER_TYPES,
|
|
68
|
+
*FLOAT_TYPES,
|
|
69
|
+
*STRING_TYPES,
|
|
70
|
+
)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Protocol, runtime_checkable
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Dtype(ABC):
|
|
8
|
+
@abstractmethod
|
|
9
|
+
def __repr__(self) -> str: ...
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@runtime_checkable
|
|
13
|
+
class Sizeable(Protocol):
|
|
14
|
+
SIZE: int
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Hierachie
|
|
2
|
+
|
|
3
|
+
```markdown
|
|
4
|
+
DataType
|
|
5
|
+
│
|
|
6
|
+
├── Primitive
|
|
7
|
+
│ ├── Boolean → 1 bit (stored bitmap; ≈ 0.125 bytes/value)
|
|
8
|
+
│ │
|
|
9
|
+
│ ├── Integer
|
|
10
|
+
│ │ ├── Signed
|
|
11
|
+
│ │ │ ├── Int8 → 1 byte
|
|
12
|
+
│ │ │ ├── Int16 → 2 bytes
|
|
13
|
+
│ │ │ ├── Int32 → 4 bytes
|
|
14
|
+
│ │ │ └── Int64 → 8 bytes
|
|
15
|
+
│ │ │
|
|
16
|
+
│ │ └── Unsigned
|
|
17
|
+
│ │ ├── UInt8 → 1 byte
|
|
18
|
+
│ │ ├── UInt16 → 2 bytes
|
|
19
|
+
│ │ ├── UInt32 → 4 bytes
|
|
20
|
+
│ │ └── UInt64 → 8 bytes
|
|
21
|
+
│ │
|
|
22
|
+
│ ├── Float
|
|
23
|
+
│ │ ├── Float16 → 2 bytes
|
|
24
|
+
│ │ ├── Float32 → 4 bytes
|
|
25
|
+
│ │ └── Float64 → 8 bytes
|
|
26
|
+
│ │
|
|
27
|
+
│ └── Decimal → 16 bytes (Decimal128) 32 bytes (Decimal256)
|
|
28
|
+
│
|
|
29
|
+
├── Temporal
|
|
30
|
+
│ ├── Date32 → 4 bytes
|
|
31
|
+
│ ├── Date64 → 8 bytes
|
|
32
|
+
│ ├── Time32 → 4 bytes
|
|
33
|
+
│ ├── Time64 → 8 bytes
|
|
34
|
+
│ ├── Timestamp → 8 bytes
|
|
35
|
+
│ └── Duration → 8 bytes
|
|
36
|
+
│
|
|
37
|
+
├── Binary
|
|
38
|
+
│ ├── Binary → variable-length
|
|
39
|
+
│ ├── LargeBinary → variable-length
|
|
40
|
+
│ ├── String → variable-length (UTF-8)
|
|
41
|
+
│ └── LargeString → variable-length (UTF-8)
|
|
42
|
+
│
|
|
43
|
+
├── Nested
|
|
44
|
+
│ ├── List → variable-length
|
|
45
|
+
│ ├── LargeList → variable-length
|
|
46
|
+
│ ├── Struct → sum of cHIGHER_BOUNDld field SIZEs
|
|
47
|
+
│ ├── Map → variable-length
|
|
48
|
+
│ └── Dictionary → index SIZE (1, 2, 4, or 8 bytes)
|
|
49
|
+
│
|
|
50
|
+
└── Null → 0 bytes
|
|
51
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import final
|
|
4
|
+
|
|
5
|
+
from typing_extensions import override
|
|
6
|
+
|
|
7
|
+
from dtypeflow.core.dtype.base import Dtype
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@final
|
|
11
|
+
class Dictionary(Dtype):
|
|
12
|
+
@override
|
|
13
|
+
def __repr__(self) -> str:
|
|
14
|
+
return f"{self.__class__.__name__}()"
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from .boolean import Boolean as BooleanDtype
|
|
4
|
+
from .float import (
|
|
5
|
+
Float as FloatDtype,
|
|
6
|
+
Float16 as Float16Dtype,
|
|
7
|
+
Float32 as Float32Dtype,
|
|
8
|
+
Float64 as Float64Dtype,
|
|
9
|
+
)
|
|
10
|
+
from .integer import (
|
|
11
|
+
Int8Dtype,
|
|
12
|
+
Int16Dtype,
|
|
13
|
+
Int32Dtype,
|
|
14
|
+
Int64Dtype,
|
|
15
|
+
IntegerDtype,
|
|
16
|
+
UInt8Dtype,
|
|
17
|
+
UInt16Dtype,
|
|
18
|
+
UInt32Dtype,
|
|
19
|
+
UInt64Dtype,
|
|
20
|
+
)
|
|
21
|
+
from .string import String as StringDtype
|
|
22
|
+
|
|
23
|
+
__all__: list[str] = [
|
|
24
|
+
"BooleanDtype",
|
|
25
|
+
"Float16Dtype",
|
|
26
|
+
"Float32Dtype",
|
|
27
|
+
"Float64Dtype",
|
|
28
|
+
"FloatDtype",
|
|
29
|
+
"Int8Dtype",
|
|
30
|
+
"Int16Dtype",
|
|
31
|
+
"Int32Dtype",
|
|
32
|
+
"Int64Dtype",
|
|
33
|
+
"IntegerDtype",
|
|
34
|
+
"StringDtype",
|
|
35
|
+
"UInt8Dtype",
|
|
36
|
+
"UInt16Dtype",
|
|
37
|
+
"UInt32Dtype",
|
|
38
|
+
"UInt64Dtype",
|
|
39
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Final, final
|
|
4
|
+
|
|
5
|
+
from typing_extensions import override
|
|
6
|
+
|
|
7
|
+
from dtypeflow.core.dtype.base import Sizeable
|
|
8
|
+
|
|
9
|
+
from .base import Primitive
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@final
|
|
13
|
+
class Boolean(Primitive, Sizeable):
|
|
14
|
+
SIZE: Final[int] = 1
|
|
15
|
+
TRUE: Final[bool] = True
|
|
16
|
+
FALSE: Final[bool] = False
|
|
17
|
+
|
|
18
|
+
@override
|
|
19
|
+
def __repr__(self) -> str:
|
|
20
|
+
return f"{self.__class__.__name__}({self.TRUE}, {self.FALSE})"
|