typol 0.0.1__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.
typol/__init__.py ADDED
@@ -0,0 +1,179 @@
1
+ """
2
+ Typol
3
+ -----
4
+
5
+ A typed wrapper around Polars, that allows static type enforcement of Polars code:
6
+
7
+ ```python
8
+ import typol as tp
9
+
10
+ class Account(tp.Shape):
11
+ name = tp.dimension(str)
12
+ website = tp.dimension(str)
13
+ account_age = tp.dimension(tp.UINT_8)
14
+ phone = tp.dimension(str)
15
+
16
+
17
+ class Contact(tp.Shape):
18
+ email = tp.dimension(str)
19
+ known_since = tp.dimension(tp.UINT_16)
20
+ phone = tp.dimension(str)
21
+
22
+
23
+ accounts.with_columns(
24
+ # This is type checked so the `+` operator must be on a number, and the used and produced
25
+ # dimensions must all be in `Account`
26
+ accounts.s.account_age + 1
27
+ )
28
+
29
+ contacts = accounts.transform(
30
+ Contact,
31
+ # This operation must only use dimensions that are available in `Account`, and must end up at
32
+ # a `Contact` dimension. All expression types are also checked to be `str`. All static checks
33
+ (accounts.s.name + "@" + accounts.s.website).to(Contact.email),
34
+ # Similar to the above, except with `int`s
35
+ (tp.lit(2026) - account.s.account_age).to(Contact.known_since),
36
+ # `phone` is in both shapes so we can leave it alone
37
+ )
38
+
39
+ emails = contacts[Contact.email].to_list()
40
+ reveal_type(emails) # list[str], Contact.known_since would reveal to `list[int]`
41
+ ```
42
+
43
+ As much of the above is statically enforced as is possible, giving much greater guarantees for
44
+ dataframe code. Where static enforcement is not possible, dynamic enforcement is used to ensure
45
+ the static types are always correct
46
+ """
47
+
48
+ from . import expr, frame, types
49
+ from .expr import (
50
+ BoundDimension,
51
+ Dimension,
52
+ Element,
53
+ EndoExpr,
54
+ ExoExpr,
55
+ Explosion,
56
+ Expr,
57
+ MesoExpr,
58
+ Shape,
59
+ Suffixed,
60
+ When,
61
+ all,
62
+ any,
63
+ arg_sort_by,
64
+ concat_list,
65
+ date,
66
+ date_range,
67
+ date_ranges,
68
+ datetime_range,
69
+ dimension,
70
+ duration,
71
+ element,
72
+ length,
73
+ lit,
74
+ max,
75
+ min,
76
+ null,
77
+ projection,
78
+ row_index,
79
+ struct,
80
+ suffix,
81
+ when,
82
+ )
83
+ from .frame import DataFrame
84
+ from .lazy import LazyFrame
85
+ from .row import Entry, Row
86
+ from .series import Series
87
+ from .types import (
88
+ BOOLEAN,
89
+ CATEGORICAL,
90
+ DATE,
91
+ DATETIME,
92
+ FLOAT_32,
93
+ FLOAT_64,
94
+ INT_8,
95
+ INT_16,
96
+ INT_32,
97
+ INT_64,
98
+ STRING,
99
+ TIME,
100
+ UINT_8,
101
+ UINT_16,
102
+ UINT_32,
103
+ UINT_64,
104
+ StructMapping,
105
+ Type,
106
+ datetime,
107
+ decimal,
108
+ enum,
109
+ list_of,
110
+ struct_of,
111
+ )
112
+
113
+ len = length
114
+
115
+ __all__ = [
116
+ "BOOLEAN",
117
+ "CATEGORICAL",
118
+ "DATE",
119
+ "DATETIME",
120
+ "FLOAT_32",
121
+ "FLOAT_64",
122
+ "INT_8",
123
+ "INT_16",
124
+ "INT_32",
125
+ "INT_64",
126
+ "STRING",
127
+ "TIME",
128
+ "UINT_8",
129
+ "UINT_16",
130
+ "UINT_32",
131
+ "UINT_64",
132
+ "BoundDimension",
133
+ "DataFrame",
134
+ "Dimension",
135
+ "Element",
136
+ "EndoExpr",
137
+ "Entry",
138
+ "ExoExpr",
139
+ "Explosion",
140
+ "Expr",
141
+ "LazyFrame",
142
+ "MesoExpr",
143
+ "Row",
144
+ "Series",
145
+ "Shape",
146
+ "StructMapping",
147
+ "Suffixed",
148
+ "Type",
149
+ "When",
150
+ "all",
151
+ "any",
152
+ "arg_sort_by",
153
+ "concat_list",
154
+ "date",
155
+ "date_range",
156
+ "date_ranges",
157
+ "datetime",
158
+ "datetime_range",
159
+ "decimal",
160
+ "dimension",
161
+ "duration",
162
+ "element",
163
+ "enum",
164
+ "expr",
165
+ "frame",
166
+ "len",
167
+ "list_of",
168
+ "lit",
169
+ "max",
170
+ "min",
171
+ "null",
172
+ "projection",
173
+ "row_index",
174
+ "struct",
175
+ "struct_of",
176
+ "suffix",
177
+ "types",
178
+ "when",
179
+ ]