feat: convert and replace timezone#6106
Conversation
Greptile OverviewGreptile SummaryThis PR implements timezone conversion and replacement functionality for timestamp types. The implementation introduces a new Key Changes:
Test Coverage:
The implementation follows Daft's new array building semantics and properly validates inputs at both the type-checking and runtime levels. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Python API
participant Series
participant UDF
participant Array
participant TimeUnit
User->>Python API: convert_time_zone(expr, to_tz, from_tz?)
Python API->>Series: dt_convert_time_zone(to_tz, from_tz?)
Series->>UDF: ConvertTimeZone::call(...)
UDF->>Array: convert_time_zone(to_tz, from_tz?)
Array->>TimeUnit: parse_timezone(to_tz)
TimeUnit-->>Array: ParsedTimezone
alt timestamp has timezone
Array->>Array: Return with updated timezone metadata
else timestamp without timezone
alt from_timezone provided
Array->>TimeUnit: parse_timezone(from_tz)
TimeUnit-->>Array: ParsedTimezone
Array->>TimeUnit: naive_local_to_timestamp(...)
TimeUnit-->>Array: converted timestamp
else from_timezone missing
Array-->>User: Error: from_timezone required
end
end
Array-->>UDF: TimestampArray
UDF-->>Series: Series
Series-->>User: Result
User->>Python API: replace_time_zone(expr, tz?)
Python API->>Series: dt_replace_time_zone(tz?)
Series->>UDF: ReplaceTimeZone::call(...)
UDF->>Array: replace_time_zone(tz?)
Array->>TimeUnit: timestamp_to_naive_local(...)
TimeUnit-->>Array: naive datetime
alt new timezone provided
Array->>TimeUnit: naive_local_to_timestamp(...)
TimeUnit-->>Array: new timestamp
else timezone = None
Array->>TimeUnit: naive_datetime_to_timestamp(...)
TimeUnit-->>Array: timestamp as UTC
end
Array-->>UDF: TimestampArray
UDF-->>Series: Series
Series-->>User: Result
Last reviewed commit: 75d6e27 |
|
@greptile-apps re-review |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6106 +/- ##
==========================================
- Coverage 43.34% 43.12% -0.23%
==========================================
Files 917 920 +3
Lines 112995 113929 +934
==========================================
+ Hits 48978 49131 +153
- Misses 64017 64798 +781
🚀 New features to boost your workflow:
|
8863882 to
a735dce
Compare
|
@greptile-apps re-review |
src/daft-core/src/array/ops/cast.rs
Outdated
| .unwrap_or_else(|_| panic!("Unable to parse timezone string {tz}")) | ||
| }); | ||
| let str_array: daft_arrow::array::Utf8Array<i64> = self | ||
| .as_arrow2() |
There was a problem hiding this comment.
nit: We'd prefer to not introduce any new arrow2 based code. Could you update this to use arrow-rs instead?
bff0bd1 to
0aad97b
Compare
c40ba3a to
75d6e27
Compare
|
rebased |
Changes Made
from_timezoneis not provided for timestamp without tz info.from_timezoneif timestamp already has tz info.timezoneis not provided.ParsedTimezoneenum to handle different timezone types (offset and tz name).Related Issues
Closes #4096.