Skip to content

Commit bd60307

Browse files
chore: Fix Ruff format and lint issues
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 29a49c6 commit bd60307

File tree

1 file changed

+55
-50
lines changed

1 file changed

+55
-50
lines changed
Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import time
21
import statistics
2+
import time
33
from datetime import datetime, timezone
4+
45
from dateutil import parser
56
from whenever import Instant, OffsetDateTime
67

78
from airbyte_cdk.utils.datetime_helpers import ab_datetime_parse
89

910
# Test formats
1011
test_formats = [
11-
'2023-03-14T15:09:26Z', # ISO format with T delimiter and Z timezone
12-
'2023-03-14T15:09:26+00:00', # ISO format with +00:00 timezone
13-
'2023-03-14T15:09:26.123456Z', # ISO format with microseconds
14-
'2023-03-14T15:09:26-04:00', # ISO format with non-UTC timezone
15-
'2023-03-14 15:09:26Z', # Missing T delimiter
16-
'2023-03-14 15:09:26', # Missing T delimiter and timezone
17-
'2023-03-14', # Date-only format
18-
'14/03/2023 15:09:26', # Different date format
19-
'2023/03/14T15:09:26Z', # Non-standard date separator
12+
"2023-03-14T15:09:26Z", # ISO format with T delimiter and Z timezone
13+
"2023-03-14T15:09:26+00:00", # ISO format with +00:00 timezone
14+
"2023-03-14T15:09:26.123456Z", # ISO format with microseconds
15+
"2023-03-14T15:09:26-04:00", # ISO format with non-UTC timezone
16+
"2023-03-14 15:09:26Z", # Missing T delimiter
17+
"2023-03-14 15:09:26", # Missing T delimiter and timezone
18+
"2023-03-14", # Date-only format
19+
"14/03/2023 15:09:26", # Different date format
20+
"2023/03/14T15:09:26Z", # Non-standard date separator
2021
]
2122

2223
# Number of iterations for each test
@@ -31,140 +32,144 @@
3132

3233
for dt_str in test_formats:
3334
print(f"\nFormat: {dt_str}")
34-
35+
3536
# Test whenever parsing
3637
whenever_times = []
3738
whenever_success = False
38-
39+
3940
# Try Instant.parse_common_iso
4041
try:
4142
# Warmup
4243
Instant.parse_common_iso(dt_str)
43-
44+
4445
for _ in range(iterations):
4546
start = time.perf_counter()
4647
Instant.parse_common_iso(dt_str)
4748
end = time.perf_counter()
4849
whenever_times.append((end - start) * 1000)
49-
50+
5051
whenever_success = True
5152
whenever_method = "Instant.parse_common_iso"
5253
except Exception:
5354
pass
54-
55+
5556
# If parse_common_iso failed, try parse_rfc3339
5657
if not whenever_success:
5758
try:
5859
# Warmup
5960
Instant.parse_rfc3339(dt_str)
60-
61+
6162
whenever_times = []
6263
for _ in range(iterations):
6364
start = time.perf_counter()
6465
Instant.parse_rfc3339(dt_str)
6566
end = time.perf_counter()
6667
whenever_times.append((end - start) * 1000)
67-
68+
6869
whenever_success = True
6970
whenever_method = "Instant.parse_rfc3339"
7071
except Exception:
7172
pass
72-
73+
7374
# If both Instant methods failed, try OffsetDateTime.parse_common_iso
7475
if not whenever_success:
7576
try:
7677
# Warmup
7778
OffsetDateTime.parse_common_iso(dt_str)
78-
79+
7980
whenever_times = []
8081
for _ in range(iterations):
8182
start = time.perf_counter()
8283
OffsetDateTime.parse_common_iso(dt_str)
8384
end = time.perf_counter()
8485
whenever_times.append((end - start) * 1000)
85-
86+
8687
whenever_success = True
8788
whenever_method = "OffsetDateTime.parse_common_iso"
8889
except Exception:
8990
whenever_method = "None"
90-
91+
9192
# Test dateutil parsing
9293
dateutil_times = []
9394
try:
9495
# Warmup
9596
parser.parse(dt_str)
96-
97+
9798
for _ in range(iterations):
9899
start = time.perf_counter()
99100
parser.parse(dt_str)
100101
end = time.perf_counter()
101102
dateutil_times.append((end - start) * 1000)
102-
103+
103104
dateutil_success = True
104105
except Exception:
105106
dateutil_success = False
106-
107+
107108
# Test ab_datetime_parse
108109
ab_times = []
109110
try:
110111
# Warmup
111112
ab_datetime_parse(dt_str)
112-
113+
113114
for _ in range(iterations):
114115
start = time.perf_counter()
115116
ab_datetime_parse(dt_str)
116117
end = time.perf_counter()
117118
ab_times.append((end - start) * 1000)
118-
119+
119120
ab_success = True
120121
except Exception:
121122
ab_success = False
122-
123+
123124
# Print results
124125
if whenever_success:
125126
whenever_avg = statistics.mean(whenever_times)
126127
whenever_min = min(whenever_times)
127128
whenever_max = max(whenever_times)
128-
print(f" {whenever_method}: avg={whenever_avg:.3f}ms, min={whenever_min:.3f}ms, max={whenever_max:.3f}ms")
129+
print(
130+
f" {whenever_method}: avg={whenever_avg:.3f}ms, min={whenever_min:.3f}ms, max={whenever_max:.3f}ms"
131+
)
129132
else:
130133
print(f" whenever: Failed to parse")
131-
134+
132135
if dateutil_success:
133136
dateutil_avg = statistics.mean(dateutil_times)
134137
dateutil_min = min(dateutil_times)
135138
dateutil_max = max(dateutil_times)
136-
print(f" dateutil.parser.parse: avg={dateutil_avg:.3f}ms, min={dateutil_min:.3f}ms, max={dateutil_max:.3f}ms")
139+
print(
140+
f" dateutil.parser.parse: avg={dateutil_avg:.3f}ms, min={dateutil_min:.3f}ms, max={dateutil_max:.3f}ms"
141+
)
137142
else:
138143
print(f" dateutil.parser.parse: Failed to parse")
139-
144+
140145
if ab_success:
141146
ab_avg = statistics.mean(ab_times)
142147
ab_min = min(ab_times)
143148
ab_max = max(ab_times)
144149
print(f" ab_datetime_parse: avg={ab_avg:.3f}ms, min={ab_min:.3f}ms, max={ab_max:.3f}ms")
145150
else:
146151
print(f" ab_datetime_parse: Failed to parse")
147-
152+
148153
# Compare performance if both succeeded
149154
if whenever_success and dateutil_success:
150155
speedup = dateutil_avg / whenever_avg
151156
print(f" Performance: whenever is {speedup:.2f}x faster than dateutil")
152-
157+
153158
# Store results for summary
154159
results[dt_str] = {
155-
'whenever': {
156-
'success': whenever_success,
157-
'method': whenever_method,
158-
'avg': statistics.mean(whenever_times) if whenever_success else None,
160+
"whenever": {
161+
"success": whenever_success,
162+
"method": whenever_method,
163+
"avg": statistics.mean(whenever_times) if whenever_success else None,
164+
},
165+
"dateutil": {
166+
"success": dateutil_success,
167+
"avg": statistics.mean(dateutil_times) if dateutil_success else None,
159168
},
160-
'dateutil': {
161-
'success': dateutil_success,
162-
'avg': statistics.mean(dateutil_times) if dateutil_success else None,
169+
"ab_datetime_parse": {
170+
"success": ab_success,
171+
"avg": statistics.mean(ab_times) if ab_success else None,
163172
},
164-
'ab_datetime_parse': {
165-
'success': ab_success,
166-
'avg': statistics.mean(ab_times) if ab_success else None,
167-
}
168173
}
169174

170175
# Print summary
@@ -174,18 +179,18 @@
174179
print("-" * 60)
175180

176181
for dt_str, result in results.items():
177-
whenever_avg = result['whenever']['avg']
178-
dateutil_avg = result['dateutil']['avg']
179-
ab_avg = result['ab_datetime_parse']['avg']
180-
182+
whenever_avg = result["whenever"]["avg"]
183+
dateutil_avg = result["dateutil"]["avg"]
184+
ab_avg = result["ab_datetime_parse"]["avg"]
185+
181186
whenever_str = f"{whenever_avg:.3f}ms" if whenever_avg else "N/A"
182187
dateutil_str = f"{dateutil_avg:.3f}ms" if dateutil_avg else "N/A"
183188
ab_str = f"{ab_avg:.3f}ms" if ab_avg else "N/A"
184-
189+
185190
if whenever_avg and dateutil_avg:
186191
speedup = dateutil_avg / whenever_avg
187192
speedup_str = f"{speedup:.2f}x"
188193
else:
189194
speedup_str = "N/A"
190-
195+
191196
print(f"{dt_str} | {whenever_str} | {dateutil_str} | {ab_str} | {speedup_str}")

0 commit comments

Comments
 (0)