Skip to content

Set timezone based on other column #11004

Answered by cpcloud
gabrielecalvo asked this question in Q&A
Discussion options

You must be logged in to vote

If you're okay with the results being in a single timezone, which is the only possibility with all the backends that Ibis supports, then you can use a scalar builtin UDF:

In [23]: from ibis.interactive import *

In [24]: t = ibis.memtable(
    ...:     {
    ...:         "ts": ["2000-01-01", "2000-01-01T12:00"],
    ...:         "zone": ["America/New_York", "Europe/Berlin"],
    ...:     }
    ...: )

In [25]: @udf.scalar.builtin
    ...: def convert_timezone(tz: str, ts) -> dt.Timestamp(timezone="UTC"):
    ...:     pass
    ...:

In [26]: convert_timezone(t.zone, t.ts.cast("timestamp"))
Out[26]:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ convert_timezone_5(zone, Cast(ts, timest…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gabrielecalvo
Comment options

Answer selected by gabrielecalvo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants