Interprets a UTC timestamp and returns the wall-clock time in the given timezone.
Mirrors Spark's from_utc_timestamp. The input is treated as a UTC instant regardless of any timezone label, and the result is a tz-naive Timestamp whose value reads as the wall-clock time in timezone.
Parameters:
| Name | Type | Description | Default |
expr | Expression | A Timestamp expression interpreted as UTC. | required |
timezone | str | Target timezone name (e.g. "America/Los_Angeles" or "+01:00"). | required |
Returns:
| Name | Type | Description |
Expression | Expression | A tz-naive Timestamp expression representing the wall-clock in timezone. |
Note
Unlike Spark, Daft does not silently resolve DST transitions during this conversion. from_utc_timestamp itself maps UTC instants to local time via :func:chrono::TimeZone::from_utc_datetime, which is unambiguous and never errors. The strict DST handling only applies to :func:to_utc_timestamp (see its docstring).
Examples:
| >>> import daft
>>> from datetime import datetime
>>> from daft.functions import from_utc_timestamp
>>> df = daft.from_pydict({"ts": [datetime(2017, 7, 14, 2, 40)]})
>>> df = df.with_column("local", from_utc_timestamp(df["ts"], "Europe/London"))
>>> df.to_pydict()["local"]
|
[datetime.datetime(2017, 7, 14, 3, 40)]
Source code in daft/functions/datetime.py
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205 | def from_utc_timestamp(expr: Expression, timezone: str) -> Expression:
"""Interprets a UTC timestamp and returns the wall-clock time in the given timezone.
Mirrors Spark's ``from_utc_timestamp``. The input is treated as a UTC instant
regardless of any timezone label, and the result is a tz-naive Timestamp whose
value reads as the wall-clock time in ``timezone``.
Args:
expr: A Timestamp expression interpreted as UTC.
timezone: Target timezone name (e.g. ``"America/Los_Angeles"`` or ``"+01:00"``).
Returns:
Expression: A tz-naive Timestamp expression representing the wall-clock in ``timezone``.
Note:
Unlike Spark, Daft does not silently resolve DST transitions during this
conversion. ``from_utc_timestamp`` itself maps UTC instants to local time
via :func:`chrono::TimeZone::from_utc_datetime`, which is unambiguous and
never errors. The strict DST handling only applies to :func:`to_utc_timestamp`
(see its docstring).
Examples:
>>> import daft
>>> from datetime import datetime
>>> from daft.functions import from_utc_timestamp
>>> df = daft.from_pydict({"ts": [datetime(2017, 7, 14, 2, 40)]})
>>> df = df.with_column("local", from_utc_timestamp(df["ts"], "Europe/London"))
>>> df.to_pydict()["local"]
[datetime.datetime(2017, 7, 14, 3, 40)]
"""
return Expression._call_builtin_scalar_fn("from_utc_timestamp", expr, timezone=timezone)
|