trinodb / trino-python-client

Python client for Trino
Apache License 2.0
307 stars 151 forks source link

Timestamp with time zone not mapped correctly #366

Closed john-bodley closed 1 year ago

john-bodley commented 1 year ago

Expected behavior

Per the Trino documentation the Trino DB-API should correctly map timestamps with time zone to Python datetime objects.

Actual behavior

Per the example provided in the Trino documentation,

from trino.dbapi import connect

cursor = connect(host="localhost").cursor()
cursor.execute("SELECT timestamp '2012-10-31 01:00 UTC' AT TIME ZONE 'America/Los_Angeles'")
rows = cursor.fetchall()
print(rows)

returns

[[datetime.datetime(2012, 10, 30, 18, 0, tzinfo=<DstTzInfo 'America/Los_Angeles' LMT-1 day, 16:07:00 STD>)]]

which is incorrect by 53 minutes due to how pytz time zones are bound. The expected outcome is

[[datetime.datetime(2012, 10, 30, 18, 0, tzinfo=<DstTzInfo 'America/Los_Angeles' PDT-1 day, 17:00:00 DST>)]]

Steps To Reproduce

See above.

Log output

This article outlines the fundamental issue which states,

pytz uses its own non-standard interface for handling time zone information that is partially but not entirely compatible with the way Python's datetime library was intended to work …

See this StackOverflow post for additional information and how time zone localization works with the pytz package.

Operating System

Ubuntu

Trino Python client version

0.321.0

Trino Server version

393.0

Python version

3.9.16

Are you willing to submit PR?

hashhar commented 1 year ago

Fixed via https://github.com/trinodb/trino-python-client/pull/368