python-datamodel 0.10.1__cp313-cp313-win32.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.
- datamodel/__init__.py +13 -0
- datamodel/abstract.py +383 -0
- datamodel/adaptive/__init__.py +0 -0
- datamodel/adaptive/models.py +598 -0
- datamodel/aliases/__init__.py +26 -0
- datamodel/base.py +180 -0
- datamodel/converters.c +43471 -0
- datamodel/converters.cp313-win32.pyd +0 -0
- datamodel/converters.html +17387 -0
- datamodel/converters.pyx +1489 -0
- datamodel/exceptions.c +13455 -0
- datamodel/exceptions.cp313-win32.pyd +0 -0
- datamodel/exceptions.html +1261 -0
- datamodel/exceptions.pxd +13 -0
- datamodel/exceptions.pyx +50 -0
- datamodel/fields.cp313-win32.pyd +0 -0
- datamodel/fields.cpp +17401 -0
- datamodel/fields.html +3912 -0
- datamodel/fields.pyx +309 -0
- datamodel/functions.cp313-win32.pyd +0 -0
- datamodel/functions.cpp +9068 -0
- datamodel/functions.html +1766 -0
- datamodel/functions.pxd +9 -0
- datamodel/functions.pyx +82 -0
- datamodel/jsonld/__init__.py +45 -0
- datamodel/jsonld/models.py +500 -0
- datamodel/libs/__init__.py +1 -0
- datamodel/libs/mapping.c +15067 -0
- datamodel/libs/mapping.cp313-win32.pyd +0 -0
- datamodel/libs/mapping.html +2618 -0
- datamodel/libs/mapping.pxd +11 -0
- datamodel/libs/mapping.pyx +135 -0
- datamodel/libs/mutables.py +127 -0
- datamodel/models.py +814 -0
- datamodel/parsers/__init__.py +0 -0
- datamodel/parsers/encoders.py +15 -0
- datamodel/parsers/json.cp313-win32.pyd +0 -0
- datamodel/parsers/json.cpp +17004 -0
- datamodel/parsers/json.html +3365 -0
- datamodel/parsers/json.pyx +250 -0
- datamodel/profiler.py +21 -0
- datamodel/py.typed +0 -0
- datamodel/rs_core/Cargo.toml +17 -0
- datamodel/rs_core/src/lib.rs +294 -0
- datamodel/rs_parsers/Cargo.toml +22 -0
- datamodel/rs_parsers/src/lib.rs +571 -0
- datamodel/rs_parsers.cp313-win32.pyd +0 -0
- datamodel/rs_validators/Cargo.toml +17 -0
- datamodel/rs_validators/src/lib.rs +0 -0
- datamodel/typedefs/__init__.py +9 -0
- datamodel/typedefs/singleton.c +9169 -0
- datamodel/typedefs/singleton.cp313-win32.pyd +0 -0
- datamodel/typedefs/singleton.html +629 -0
- datamodel/typedefs/singleton.pxd +9 -0
- datamodel/typedefs/singleton.pyx +24 -0
- datamodel/typedefs/types.c +11716 -0
- datamodel/typedefs/types.cp313-win32.pyd +0 -0
- datamodel/typedefs/types.html +732 -0
- datamodel/typedefs/types.pxd +11 -0
- datamodel/typedefs/types.pyx +39 -0
- datamodel/types.c +7165 -0
- datamodel/types.cp313-win32.pyd +0 -0
- datamodel/types.html +716 -0
- datamodel/types.pyx +100 -0
- datamodel/validation.cp313-win32.pyd +0 -0
- datamodel/validation.cpp +17085 -0
- datamodel/validation.html +4769 -0
- datamodel/validation.pyx +315 -0
- datamodel/version.py +13 -0
- examples/nn/examples.py +311 -0
- examples/nn/stores.py +151 -0
- examples/tests/sp_types.py +294 -0
- examples/tests/speed_dates.py +26 -0
- python_datamodel-0.10.1.dist-info/LICENSE +29 -0
- python_datamodel-0.10.1.dist-info/METADATA +320 -0
- python_datamodel-0.10.1.dist-info/RECORD +78 -0
- python_datamodel-0.10.1.dist-info/WHEEL +5 -0
- python_datamodel-0.10.1.dist-info/top_level.txt +7 -0
examples/nn/stores.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
store_payload = """
|
|
2
|
+
{
|
|
3
|
+
"batch_id": "e5c9f191-698e-49f9-9a50-8bdc60d860c3",
|
|
4
|
+
"data": [
|
|
5
|
+
{
|
|
6
|
+
"metadata": {
|
|
7
|
+
"type": "store",
|
|
8
|
+
"transaction_type": "UPSERT",
|
|
9
|
+
"source": "MainEvent",
|
|
10
|
+
"client": "wm_assembly",
|
|
11
|
+
"client_id": 61,
|
|
12
|
+
"orgid": 71,
|
|
13
|
+
"timestamp": 1738289810.605841
|
|
14
|
+
},
|
|
15
|
+
"payload": {
|
|
16
|
+
"store_name": "KILMARNOCK-4350",
|
|
17
|
+
"store_address": "200 Old Fair Grounds Way",
|
|
18
|
+
"city": "Kilmarnock",
|
|
19
|
+
"zipcode": "22482",
|
|
20
|
+
"phone_number": null,
|
|
21
|
+
"email_address": null,
|
|
22
|
+
"store_number": 20560,
|
|
23
|
+
"store_status": "t",
|
|
24
|
+
"latitude": "37.727116",
|
|
25
|
+
"longitude": "-76.385085",
|
|
26
|
+
"timezone": "America/New_York",
|
|
27
|
+
"account_id": 19,
|
|
28
|
+
"country_id": "USA",
|
|
29
|
+
"created_at": "2024-09-23T07:50:33-05:00",
|
|
30
|
+
"updated_at": "2025-01-30T20:16:50-06:00",
|
|
31
|
+
"store_id": 20560,
|
|
32
|
+
"store_type": "FreeStanding",
|
|
33
|
+
"account_name": "Walmart Assembly",
|
|
34
|
+
"orgid": [
|
|
35
|
+
71
|
|
36
|
+
],
|
|
37
|
+
"client_id": [
|
|
38
|
+
61
|
|
39
|
+
],
|
|
40
|
+
"client_name": [
|
|
41
|
+
"TRO Walmart Assembly"
|
|
42
|
+
],
|
|
43
|
+
"custom_fields": [
|
|
44
|
+
{
|
|
45
|
+
"custom_id": 79,
|
|
46
|
+
"custom_name": "Store Number",
|
|
47
|
+
"custom_value": "BBY4350",
|
|
48
|
+
"custom_orgid": null,
|
|
49
|
+
"custom_client_id": 1
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"custom_id": 33,
|
|
53
|
+
"custom_name": "Store Name",
|
|
54
|
+
"custom_value": "Best Buy 4350",
|
|
55
|
+
"custom_orgid": null,
|
|
56
|
+
"custom_client_id": 1
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"custom_id": 35,
|
|
60
|
+
"custom_name": "effective_date",
|
|
61
|
+
"custom_value": null,
|
|
62
|
+
"custom_orgid": null,
|
|
63
|
+
"custom_client_id": 1
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"custom_id": 30,
|
|
67
|
+
"custom_name": "latitude",
|
|
68
|
+
"custom_value": null,
|
|
69
|
+
"custom_orgid": null,
|
|
70
|
+
"custom_client_id": 1
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"custom_id": 31,
|
|
74
|
+
"custom_name": "longitude",
|
|
75
|
+
"custom_value": null,
|
|
76
|
+
"custom_orgid": null,
|
|
77
|
+
"custom_client_id": 1
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"custom_id": 32,
|
|
81
|
+
"custom_name": "phone_number",
|
|
82
|
+
"custom_value": null,
|
|
83
|
+
"custom_orgid": null,
|
|
84
|
+
"custom_client_id": 1
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"custom_id": 72,
|
|
88
|
+
"custom_name": "Timezone ID",
|
|
89
|
+
"custom_value": null,
|
|
90
|
+
"custom_orgid": null,
|
|
91
|
+
"custom_client_id": 1
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"custom_id": 46,
|
|
95
|
+
"custom_name": "Full Name",
|
|
96
|
+
"custom_value": "Thornton, Roderick Lemel",
|
|
97
|
+
"custom_orgid": 71,
|
|
98
|
+
"custom_client_id": 61
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"custom_id": 47,
|
|
102
|
+
"custom_name": "Store Designation",
|
|
103
|
+
"custom_value": "15",
|
|
104
|
+
"custom_orgid": 71,
|
|
105
|
+
"custom_client_id": 61
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"custom_id": 42,
|
|
109
|
+
"custom_name": "Store Name",
|
|
110
|
+
"custom_value": "BBY4350",
|
|
111
|
+
"custom_orgid": 71,
|
|
112
|
+
"custom_client_id": 61
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"custom_id": 45,
|
|
116
|
+
"custom_name": "username",
|
|
117
|
+
"custom_value": "rthornton@trocglobal.com",
|
|
118
|
+
"custom_orgid": 71,
|
|
119
|
+
"custom_client_id": 61
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"custom_id": 43,
|
|
123
|
+
"custom_name": "Visit Category",
|
|
124
|
+
"custom_value": "12",
|
|
125
|
+
"custom_orgid": 71,
|
|
126
|
+
"custom_client_id": 61
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"custom_id": 44,
|
|
130
|
+
"custom_name": "Visit Rule",
|
|
131
|
+
"custom_value": "1.00",
|
|
132
|
+
"custom_orgid": 71,
|
|
133
|
+
"custom_client_id": 61
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
"market_name": {
|
|
137
|
+
"71": "10"
|
|
138
|
+
},
|
|
139
|
+
"region_name": {
|
|
140
|
+
"71": "Assembly - Region"
|
|
141
|
+
},
|
|
142
|
+
"district_name": {
|
|
143
|
+
"71": "Assembly - District"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
"timestamp": "2025-01-31T02:17:03.007Z",
|
|
149
|
+
"_id": "679c329f54ed69a5e38d7d12"
|
|
150
|
+
}
|
|
151
|
+
"""
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import timeit
|
|
2
|
+
import uuid
|
|
3
|
+
import datetime
|
|
4
|
+
import rs_parsers
|
|
5
|
+
from datamodel.converters import (
|
|
6
|
+
to_string,
|
|
7
|
+
to_date,
|
|
8
|
+
to_datetime,
|
|
9
|
+
to_uuid,
|
|
10
|
+
to_integer,
|
|
11
|
+
to_float,
|
|
12
|
+
to_decimal,
|
|
13
|
+
# strtobool,
|
|
14
|
+
to_boolean
|
|
15
|
+
)
|
|
16
|
+
from decimal import Decimal
|
|
17
|
+
|
|
18
|
+
# print('==== STRING TO BOOL =====')
|
|
19
|
+
|
|
20
|
+
# def ct_str_to_bool():
|
|
21
|
+
# for _ in range(1, 10):
|
|
22
|
+
# obj = strtobool('True')
|
|
23
|
+
# obj = strtobool('False')
|
|
24
|
+
# obj = strtobool('true')
|
|
25
|
+
# obj = strtobool('false')
|
|
26
|
+
# obj = strtobool('TRUE')
|
|
27
|
+
# obj = strtobool('FALSE')
|
|
28
|
+
# obj = strtobool('1')
|
|
29
|
+
# obj = strtobool('0')
|
|
30
|
+
# obj = strtobool('yes')
|
|
31
|
+
# obj = strtobool('no')
|
|
32
|
+
# obj = strtobool('YES')
|
|
33
|
+
# obj = strtobool('NO')
|
|
34
|
+
# assert isinstance(obj, bool)
|
|
35
|
+
|
|
36
|
+
# def rs_str_to_bool():
|
|
37
|
+
# for _ in range(1, 10):
|
|
38
|
+
# obj = rs_parsers.strtobool('True')
|
|
39
|
+
# obj = rs_parsers.strtobool('False')
|
|
40
|
+
# obj = rs_parsers.strtobool('true')
|
|
41
|
+
# obj = rs_parsers.strtobool('false')
|
|
42
|
+
# obj = rs_parsers.strtobool('TRUE')
|
|
43
|
+
# obj = rs_parsers.strtobool('FALSE')
|
|
44
|
+
# obj = rs_parsers.strtobool('1')
|
|
45
|
+
# obj = rs_parsers.strtobool('0')
|
|
46
|
+
# obj = rs_parsers.strtobool('yes')
|
|
47
|
+
# obj = rs_parsers.strtobool('no')
|
|
48
|
+
# obj = rs_parsers.strtobool('YES')
|
|
49
|
+
# obj = rs_parsers.strtobool('NO')
|
|
50
|
+
# assert isinstance(obj, bool)
|
|
51
|
+
|
|
52
|
+
# print('Test with Cython: ')
|
|
53
|
+
# time = timeit.timeit(ct_str_to_bool, number=100000)
|
|
54
|
+
# print(f"Execution time: {time:.6f} seconds")
|
|
55
|
+
|
|
56
|
+
# print('Test with Rust: ')
|
|
57
|
+
# time = timeit.timeit(rs_str_to_bool, number=100000)
|
|
58
|
+
# print(f"Execution time: {time:.6f} seconds")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
print('======== BOOLEAN ======')
|
|
62
|
+
|
|
63
|
+
def ct_to_boolean():
|
|
64
|
+
for _ in range(1, 10):
|
|
65
|
+
obj = to_boolean('True')
|
|
66
|
+
obj = to_boolean('False')
|
|
67
|
+
obj = to_boolean('true')
|
|
68
|
+
obj = to_boolean('false')
|
|
69
|
+
obj = to_boolean('TRUE')
|
|
70
|
+
obj = to_boolean('FALSE')
|
|
71
|
+
obj = to_boolean('1')
|
|
72
|
+
obj = to_boolean('0')
|
|
73
|
+
obj = to_boolean('yes')
|
|
74
|
+
obj = to_boolean('no')
|
|
75
|
+
obj = to_boolean('YES')
|
|
76
|
+
obj = to_boolean('NO')
|
|
77
|
+
assert isinstance(obj, bool)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
print('Test with Cython: ')
|
|
81
|
+
time = timeit.timeit(ct_to_boolean, number=100000)
|
|
82
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
83
|
+
|
|
84
|
+
print('=========== STRINGS ============== ')
|
|
85
|
+
|
|
86
|
+
def ct_to_string():
|
|
87
|
+
for _ in range(1, 10):
|
|
88
|
+
obj = to_string(b'\x00')
|
|
89
|
+
obj = to_string(1234)
|
|
90
|
+
assert isinstance(obj, str)
|
|
91
|
+
|
|
92
|
+
print('Test with Cython: ')
|
|
93
|
+
time = timeit.timeit(ct_to_string, number=100000)
|
|
94
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def rs_to_string():
|
|
98
|
+
for _ in range(1, 10):
|
|
99
|
+
obj = rs_parsers.to_string(b'\x00')
|
|
100
|
+
obj = rs_parsers.to_string(1234)
|
|
101
|
+
assert isinstance(obj, str)
|
|
102
|
+
|
|
103
|
+
print('Test with Rust: ')
|
|
104
|
+
time = timeit.timeit(ct_to_string, number=100000)
|
|
105
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
106
|
+
|
|
107
|
+
print('=========== DATES ============== ')
|
|
108
|
+
|
|
109
|
+
def ct_to_dates():
|
|
110
|
+
for _ in range(1, 10):
|
|
111
|
+
# obj = to_date(datetime.datetime.now())
|
|
112
|
+
obj = to_date('2028-01-01')
|
|
113
|
+
assert isinstance(obj, datetime.date)
|
|
114
|
+
|
|
115
|
+
print('Test with Cython: ')
|
|
116
|
+
time = timeit.timeit(ct_to_dates, number=100000)
|
|
117
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def rs_to_dates():
|
|
121
|
+
for _ in range(1, 10):
|
|
122
|
+
# obj = rs_parsers.to_date(datetime.datetime.now())
|
|
123
|
+
obj = rs_parsers.to_date('2028-01-01')
|
|
124
|
+
assert isinstance(obj, datetime.date)
|
|
125
|
+
|
|
126
|
+
print('Test with Rust: ')
|
|
127
|
+
time = timeit.timeit(rs_to_dates, number=100000)
|
|
128
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
print('=========== DATETIMES ============== ')
|
|
132
|
+
|
|
133
|
+
def ct_to_datetimes():
|
|
134
|
+
for _ in range(1, 10):
|
|
135
|
+
# obj = to_datetime(datetime.datetime.now())
|
|
136
|
+
obj = to_datetime('2028-01-01 12:00:00')
|
|
137
|
+
assert isinstance(obj, datetime.datetime)
|
|
138
|
+
|
|
139
|
+
def rs_to_datetimes():
|
|
140
|
+
for _ in range(1, 10):
|
|
141
|
+
# obj = rs_parsers.to_datetime(datetime.datetime.now())
|
|
142
|
+
obj = rs_parsers.to_datetime('2028-01-01 12:00:00')
|
|
143
|
+
assert isinstance(obj, datetime.datetime)
|
|
144
|
+
|
|
145
|
+
print('Test with Cython: ')
|
|
146
|
+
time = timeit.timeit(ct_to_datetimes, number=100000)
|
|
147
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
148
|
+
|
|
149
|
+
print('Test with Rust: ')
|
|
150
|
+
time = timeit.timeit(rs_to_datetimes, number=100000)
|
|
151
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
152
|
+
|
|
153
|
+
print('================== UUID ======================')
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def ct_uuid():
|
|
157
|
+
for _ in range(1, 10):
|
|
158
|
+
obj = to_uuid("550e8400-e29b-41d4-a716-446655440000") # UUID object
|
|
159
|
+
obj = to_uuid(uuid.UUID("550e8400-e29b-41d4-a716-446655440000")) # Same UUID
|
|
160
|
+
obj = to_uuid(lambda: "550e8400-e29b-41d4-a716-446655440000") # Callable
|
|
161
|
+
_ = to_uuid("not-a-uuid") # None
|
|
162
|
+
assert isinstance(obj, uuid.UUID)
|
|
163
|
+
|
|
164
|
+
def rs_uuid():
|
|
165
|
+
for _ in range(1, 10):
|
|
166
|
+
obj = rs_parsers.to_uuid_str("550e8400-e29b-41d4-a716-446655440000") # UUID object
|
|
167
|
+
obj = rs_parsers.to_uuid_str(uuid.UUID("550e8400-e29b-41d4-a716-446655440000")) # Same UUID
|
|
168
|
+
obj = rs_parsers.to_uuid_str(lambda: "550e8400-e29b-41d4-a716-446655440000") # Callable
|
|
169
|
+
_ = rs_parsers.to_uuid_str("not-a-uuid") # None
|
|
170
|
+
assert isinstance(obj, uuid.UUID)
|
|
171
|
+
|
|
172
|
+
def rs_uuid_native():
|
|
173
|
+
for _ in range(1, 10):
|
|
174
|
+
obj = rs_parsers.to_uuid("550e8400-e29b-41d4-a716-446655440000") # UUID object
|
|
175
|
+
obj = rs_parsers.to_uuid(uuid.UUID("550e8400-e29b-41d4-a716-446655440000")) # Same UUID
|
|
176
|
+
obj = rs_parsers.to_uuid(lambda: "550e8400-e29b-41d4-a716-446655440000") # Callable
|
|
177
|
+
_ = rs_parsers.to_uuid("not-a-uuid") # None
|
|
178
|
+
assert isinstance(obj, uuid.UUID)
|
|
179
|
+
|
|
180
|
+
print('Test with Cython: ')
|
|
181
|
+
time = timeit.timeit(ct_uuid, number=10000)
|
|
182
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
183
|
+
|
|
184
|
+
print('Test with Rust: ')
|
|
185
|
+
time = timeit.timeit(rs_uuid, number=10000)
|
|
186
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
187
|
+
|
|
188
|
+
print('Test with Rust Native: ')
|
|
189
|
+
time = timeit.timeit(rs_uuid_native, number=10000)
|
|
190
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
print('================== INTEGERS ======================')
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def ct_integers():
|
|
197
|
+
for _ in range(1, 10):
|
|
198
|
+
obj = to_integer(42) # ✅ 42
|
|
199
|
+
obj = to_integer("100") # ✅ 100
|
|
200
|
+
obj = to_integer(lambda: "123") # ✅ 123
|
|
201
|
+
obj = to_integer(None) # ✅ None
|
|
202
|
+
try:
|
|
203
|
+
_ = to_integer("invalid") # ❌ Raises ValueError
|
|
204
|
+
except ValueError:
|
|
205
|
+
pass
|
|
206
|
+
|
|
207
|
+
def rs_integers():
|
|
208
|
+
for _ in range(1, 10):
|
|
209
|
+
obj = rs_parsers.to_integer(42) # ✅ 42
|
|
210
|
+
obj = rs_parsers.to_integer("100") # ✅ 100
|
|
211
|
+
obj = rs_parsers.to_integer(lambda: "123") # ✅ 123
|
|
212
|
+
obj = rs_parsers.to_integer(None) # ✅ None
|
|
213
|
+
try:
|
|
214
|
+
_ = rs_parsers.to_integer("invalid") # ❌ Raises ValueError
|
|
215
|
+
except ValueError:
|
|
216
|
+
pass
|
|
217
|
+
|
|
218
|
+
print('Test with Cython: ')
|
|
219
|
+
time = timeit.timeit(ct_integers, number=10000)
|
|
220
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
221
|
+
|
|
222
|
+
print('Test with Rust: ')
|
|
223
|
+
time = timeit.timeit(rs_integers, number=10000)
|
|
224
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
print('================== FLOATS ======================')
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def ct_floats():
|
|
231
|
+
for _ in range(1, 10):
|
|
232
|
+
obj = to_float(3.14) # ✅ 3.14
|
|
233
|
+
obj = to_float("2.71") # ✅ 2.71
|
|
234
|
+
obj = to_float(lambda: "1.618") # ✅ 1.618
|
|
235
|
+
obj = to_float(None) # ✅ None
|
|
236
|
+
try:
|
|
237
|
+
_ = to_float("invalid") # ❌ Raises ValueError
|
|
238
|
+
except ValueError:
|
|
239
|
+
pass
|
|
240
|
+
|
|
241
|
+
def rs_floats():
|
|
242
|
+
for _ in range(1, 10):
|
|
243
|
+
obj = rs_parsers.to_float(3.14) # ✅ 3.14
|
|
244
|
+
obj = rs_parsers.to_float("2.71")
|
|
245
|
+
obj = rs_parsers.to_float(lambda: "1.618") # ✅ 1.618
|
|
246
|
+
obj = rs_parsers.to_float(None) # ✅ None
|
|
247
|
+
try:
|
|
248
|
+
_ = rs_parsers.to_float("invalid") # ❌ Raises ValueError
|
|
249
|
+
except ValueError:
|
|
250
|
+
pass
|
|
251
|
+
|
|
252
|
+
print('Test with Cython: ')
|
|
253
|
+
time = timeit.timeit(ct_floats, number=10000)
|
|
254
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
255
|
+
|
|
256
|
+
print('Test with Rust: ')
|
|
257
|
+
time = timeit.timeit(rs_floats, number=10000)
|
|
258
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
print('============ DECIMALS =============================')
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def ct_decimals():
|
|
265
|
+
for _ in range(1, 10):
|
|
266
|
+
obj = to_decimal(Decimal("10.5"))
|
|
267
|
+
obj = to_decimal("100.1234")
|
|
268
|
+
obj = to_decimal(lambda: "3.1415")
|
|
269
|
+
obj = to_decimal(42.56)
|
|
270
|
+
obj = to_decimal(None)
|
|
271
|
+
try:
|
|
272
|
+
_ = to_decimal("not-a-decimal")
|
|
273
|
+
except ValueError:
|
|
274
|
+
pass
|
|
275
|
+
|
|
276
|
+
def rs_decimals():
|
|
277
|
+
for _ in range(1, 10):
|
|
278
|
+
obj = rs_parsers.to_decimal(Decimal("10.5"))
|
|
279
|
+
obj = rs_parsers.to_decimal("100.1234")
|
|
280
|
+
obj = rs_parsers.to_decimal(lambda: "3.1415")
|
|
281
|
+
obj = rs_parsers.to_decimal(42.56)
|
|
282
|
+
obj = rs_parsers.to_decimal(None)
|
|
283
|
+
try:
|
|
284
|
+
_ = rs_parsers.to_decimal("not-a-decimal")
|
|
285
|
+
except ValueError:
|
|
286
|
+
pass
|
|
287
|
+
|
|
288
|
+
print('Test with Cython: ')
|
|
289
|
+
time = timeit.timeit(ct_decimals, number=100)
|
|
290
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
291
|
+
|
|
292
|
+
print('Test with Rust: ')
|
|
293
|
+
time = timeit.timeit(rs_decimals, number=100)
|
|
294
|
+
print(f"Execution time: {time:.6f} seconds")
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import timeit
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
import pendulum
|
|
4
|
+
import ciso8601
|
|
5
|
+
|
|
6
|
+
def ciso():
|
|
7
|
+
obj = '1978-10-23'
|
|
8
|
+
return ciso8601.parse_datetime(obj).date()
|
|
9
|
+
|
|
10
|
+
def pend():
|
|
11
|
+
obj = '23-10-1978'
|
|
12
|
+
return pendulum.parse(obj, strict=False).date()
|
|
13
|
+
|
|
14
|
+
def strf():
|
|
15
|
+
obj = '1978-10-23'
|
|
16
|
+
return datetime.strptime(obj, "%Y-%m-%d").date()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
time = timeit.timeit(ciso, number=10000)
|
|
20
|
+
print(f"CISO Execution time: {time:.6f} seconds")
|
|
21
|
+
|
|
22
|
+
time = timeit.timeit(pend, number=10000)
|
|
23
|
+
print(f"Pendulum Execution time: {time:.6f} seconds")
|
|
24
|
+
|
|
25
|
+
time = timeit.timeit(strf, number=10000)
|
|
26
|
+
print(f"Strptime Execution time: {time:.6f} seconds")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022, phenobarbital
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|